Submission #1370334


Source Code Expand

#include <map>
#include <set>
#include <list>
#include <cmath>
#include <ctime>
#include <deque>
#include <queue>
#include <stack>
#include <string>
#include <bitset>
#include <cstdio>
#include <limits>
#include <vector>
#include <climits>
#include <cstring>
#include <cstdlib>
#include <fstream>
#include <numeric>
#include <sstream>
#include <cassert>
#include <iomanip>
#include <iostream>
#include <algorithm>
#include <unordered_set>
#include <unordered_map>

using namespace std;

#define f first
#define s second
#define pb push_back
#define pp pop_back
#define mp make_pair
#define ll long long
#define ld double
#define ull unsigned long long
#define PI pair < int, int > 

const int N = 5e5 + 123;
const int M = 123;
const ld Pi = acos(-1);
const ll Inf = 1e18;
const int inf = 1e9;
const int mod = 1e9 + 7;
const int Sz = 501;
const int MOD = 1e9 + 7;

void add(int &a, int b) {
  a += b;
  if (a >= mod) a -= mod;
}
int mult(int a, int b) {
  return 1ll * a * b % mod;
}
int sum(int a, int b) {
  add(a, b);
  return a;
}

int n, a[N], ans;
ll p[N];

void solve() { 
  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];
//  for (int i = 1;i <= n;i++) cout << a[i] << " "; cout << endl;
  ll now = 0;
  for (int i = 1;i <= n;i++) {
    now += a[i];
    int pos = i + 1;
    bool fail = 0;
   // cout << "i = " << i << endl;
    ll old = now;
    while(pos <= n) {
     // cout << "pos = " << pos << endl;
      int l = pos, r = n, nxt = -1;
      while(l <= r) {
        int mid = (l + r) / 2;
        if (a[mid] <= 2 * now) {
          nxt = mid;
          l = mid + 1;
        } else r = mid - 1;
      }
      if (nxt == -1) {
        fail = 1;
        break;
      }
      now += p[nxt] - p[pos - 1];
      pos = nxt + 1;
    }
    if (!fail) ans++;
    now = old;
  }
  cout << ans << endl;
}

int main() {
  #ifdef wws
   freopen("in", "r", stdin);
   // freopen("in", "w", stdout);
  #endif 
  ios_base::sync_with_stdio(0);
  int tt = 1; 
  while(tt--) solve();
  return 0;
}

Submission Info

Submission Time
Task B - Colorful Creatures
User SmallBoy
Language C++14 (GCC 5.4.1)
Score 400
Code Size 2182 Byte
Status AC
Exec Time 27 ms
Memory 3328 KB

Judge Result

Set Name Sample All
Score / Max Score 0 / 0 400 / 400
Status
AC × 3
AC × 19
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 22 ms 3328 KB
in10.txt AC 10 ms 2688 KB
in11.txt AC 27 ms 3328 KB
in12.txt AC 17 ms 3328 KB
in13.txt AC 17 ms 3328 KB
in2.txt AC 22 ms 3328 KB
in3.txt AC 22 ms 3328 KB
in4.txt AC 22 ms 3328 KB
in5.txt AC 9 ms 2560 KB
in6.txt AC 22 ms 3328 KB
in7.txt AC 22 ms 3328 KB
in8.txt AC 22 ms 3328 KB
in9.txt AC 4 ms 2432 KB
sample1.txt AC 2 ms 2304 KB
sample2.txt AC 2 ms 2304 KB
sample3.txt AC 2 ms 2304 KB