Saturday, July 19, 2014

codeforces VK Cup 2012 Round 1, problem: (A) Dress'em in Vests! solution

codeforces VK Cup 2012 Round 1, problem: (A) Dress'em in Vests!: http://codeforces.com/problemset/problem/161/A

codeforces VK Cup 2012 Round 1, problem: (A) Dress'em in Vests! editorial: http://codeforces.com/blog/entry/4097

codeforces VK Cup 2012 Round 1, problem: (A) Dress'em in Vests! solution: http://ideone.com/tuhMnW


#include <iostream>
#include <cstdio>
#include <algorithm>
using namespace std;

int main() {
    int n, m, x, y, a[100005]={0}, b[100005]={0}, cnt=0, k=0, c[100005]={0}, d[100005]={0};
    scanf("%d%d%d%d", &n, &m, &x, &y);
    for(int i=0; i<n; i++) scanf("%d", &a[i]);
    for(int j=0; j<m; j++) scanf("%d", &b[j]);
    sort(a, a+n), sort(b, b+m);
    for(int i=0; i<n; i++) {
        while(a[i]-x>b[k] && k<m) k++; 
        if(a[i]+y<b[k]) continue;
        if(k==m) break;
        c[cnt]=i+1, d[cnt]=k+1, cnt++, k++;
    }
    printf("%d\n", cnt);
    for(int i=0; i<cnt; i++) printf("%d %d\n", c[i], d[i]);
    return 0;
}


No comments:

Post a Comment