fork download
  1. #include <iostream>
  2. #include <cstdio>
  3. #include <algorithm>
  4. using namespace std;
  5.  
  6. int main() {
  7. int n, a[500005], cnt=0, b[500005]={0}, j;
  8. scanf("%d", &n), j=n/2-1;
  9. for(int i=0; i<n; i++) scanf("%d", &a[i]);
  10. sort(a, a+n);
  11. for(int i=n-1; i>=0; i--) if(b[i]==0) {
  12. while(a[j]>a[i]/2 && j>=0) j--;
  13. while(b[j]==1 && j>=0) j--;
  14. if(j<0) break;
  15. if(b[j]==0 && a[j]<=a[i]/2) b[i]=b[j]=1, cnt++;
  16. }
  17. printf("%d", n-cnt);
  18. return 0;
  19. }
Success #stdin #stdout 0s 7136KB
stdin
100
154
60
97
638
139
150
570
579
601
647
804
237
245
549
288
347
778
282
916
441
974
145
957
886
655
702
930
618
132
520
972
48
94
54
682
433
896
134
845
636
242
842
125
141
240
130
409
666
948
938
604
110
474
484
364
40
807
271
438
288
201
814
754
589
341
576
146
952
819
923
222
535
336
83
314
911
303
911
384
601
249
330
735
271
142
204
405
783
775
449
590
139
109
276
45
205
454
836
82
841
stdout
50