Wednesday, July 16, 2014

Codeforces Round #113 (Div. 2), problem: (A) Rank List solution

Codeforces Round #113 (Div. 2), problem: (A) Rank List: http://codeforces.com/problemset/problem/166/A

Codeforces Round #113 (Div. 2), problem: (A) Rank List editorial: http://codeforces.com/blog/entry/4173

Codeforces Round #113 (Div. 2), problem: (A) Rank List solution: http://ideone.com/iEgAy0


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

int main() {
    int k, n, ans=0;
    pair <int, int> p[55];
    scanf("%d%d", &n, &k);
    for(int i=0; i<n; i++) scanf("%d%d", &p[i].first, &p[i].second), p[i].first*=-1;
    sort(p, p+n);
    for(int i=0; i<n; i++) if(p[i]==p[k-1]) ans++;
    printf("%d", ans);
    return 0;
}

the above code works fine, but code below does not work, the compiler gives error for "operand[]" but i dont know the exact reason.
#include <iostream>
#include <cstdio>
#include <algorithm>
using namespace std;

int main() {
    int k, n, ans=0;
    pair <int, int> p;
    scanf("%d%d", &n, &k);
    for(int i=0; i<n; i++) scanf("%d%d", &p[i].first, &p[i].second), p[i].first*=-1;
    sort(p, p+n);
    for(int i=0; i<n; i++) if(p[i]==p[k-1]) ans++;
    printf("%d", ans);
    return 0;
}


1 comment:

  1. You haven't declared the size of the pair in latter snippet of code.

    ReplyDelete