Codeforces Round #219 (Div. 1), problem: (A) Counting Kangaroos is Fun editorial: http://codeforces.com/blog/entry/9944
Codeforces Round #219 (Div. 1), problem: (A) Counting Kangaroos is Fun solution: http://ideone.com/RJ0rBv
#include <iostream> #include <cstdio> #include <algorithm> using namespace std; int main() { int n, a[500005], cnt=0, b[500005]={0}, j; scanf("%d", &n), j=n/2-1; for(int i=0; i<n; i++) scanf("%d", &a[i]); sort(a, a+n); for(int i=n-1; i>=0; i--) if(b[i]==0) { while(a[j]>a[i]/2 && j>=0) j--; while(b[j]==1 && j>=0) j--; if(j<0) break; if(b[j]==0 && a[j]<=a[i]/2) b[i]=b[j]=1, cnt++; } printf("%d", n-cnt); return 0; }
No comments:
Post a Comment