Submission #1370370
Source Code Expand
#include <bits/stdc++.h> using namespace std; typedef long long ll; typedef pair <int, int> pii; #define fr first #define sc second #define pb push_back #define mpr make_pair #define ppb pop_back() #define ins insert #define sz(s) int(s.size()) #define all(x) x.begin(), x.end() #define lb lower_bound #define ub upper_bound const int N = 1e5 + 1; ll p[N]; int a[N], n; bool check(int x){ ll sum = p[x]; for(int i = x + 1;i <= n; ++ i){ if(a[i] > sum * 2)return 0; sum += a[i]; } return 1; } int main() { ios_base :: sync_with_stdio(0); cin.tie(0); cout.tie(0); cin >> n; for(int i = 1;i <= n; ++ i){ cin >> a[i]; } sort(a + 1,a + n + 1); for(int i = 1;i <= n; ++ i){ p[i] = p[i - 1] + a[i]; } int l = 1,r = n; while(l < r){ int mid = (l + r) / 2; if(check(mid))r = mid; else l = mid + 1; } cout << n - l + 1; return 0; }
Submission Info
Submission Time | |
---|---|
Task | B - Colorful Creatures |
User | Manas |
Language | C++14 (GCC 5.4.1) |
Score | 400 |
Code Size | 903 Byte |
Status | AC |
Exec Time | 19 ms |
Memory | 1408 KB |
Judge Result
Set Name | Sample | All | ||||
---|---|---|---|---|---|---|
Score / Max Score | 0 / 0 | 400 / 400 | ||||
Status |
|
|
Set Name | Test Cases |
---|---|
Sample | sample1.txt, sample2.txt, sample3.txt |
All | sample1.txt, sample2.txt, sample3.txt, in1.txt, in10.txt, in11.txt, in12.txt, in13.txt, in2.txt, in3.txt, in4.txt, in5.txt, in6.txt, in7.txt, in8.txt, in9.txt, sample1.txt, sample2.txt, sample3.txt |
Case Name | Status | Exec Time | Memory |
---|---|---|---|
in1.txt | AC | 19 ms | 1408 KB |
in10.txt | AC | 7 ms | 768 KB |
in11.txt | AC | 17 ms | 1408 KB |
in12.txt | AC | 14 ms | 1408 KB |
in13.txt | AC | 14 ms | 1408 KB |
in2.txt | AC | 19 ms | 1408 KB |
in3.txt | AC | 19 ms | 1408 KB |
in4.txt | AC | 19 ms | 1408 KB |
in5.txt | AC | 8 ms | 768 KB |
in6.txt | AC | 15 ms | 1408 KB |
in7.txt | AC | 18 ms | 1408 KB |
in8.txt | AC | 15 ms | 1408 KB |
in9.txt | AC | 3 ms | 384 KB |
sample1.txt | AC | 1 ms | 256 KB |
sample2.txt | AC | 1 ms | 256 KB |
sample3.txt | AC | 1 ms | 256 KB |