Submission #918015

# Submission time Handle Problem Language Result Execution time Memory
918015 2024-01-29T11:37:18 Z abczz Sails (IOI07_sails) C++14
55 / 100
56 ms 2804 KB
#include <iostream>
#include <vector>
#include <array>
#define ll long long

using namespace std;

bool ok;
vector <ll> V;
ll n, a, b, k, l, r, z, mid, s, t, f, ps[100001], dlt[100001], cnt[100001];

int main() {
  cin >> n;
  for (int i=0; i<n; ++i) {
    cin >> a >> b;
    --a;
    ps[a] += b;
    t += b;
    ++cnt[a+1];
  }
  for (int i=1; i<100000; ++i) {
    ps[i] += ps[i-1];
    cnt[i] += cnt[i-1];
  }
  l = 0, r = n;
  while (l < r) {
    mid = (l+r)/2;
    s = 0;
    ok = 1;
    for (int i=0; i<100000; ++i) {
      s += min(n-cnt[i], mid);
      if (s < ps[i]) {
        ok = 0;
        break;
      }
    }
    if (ok) r = mid;
    else l = mid+1;
  }
  for (int i=0; i<100000; ++i) {
    s = min(n-cnt[i], l);
    z += s;
    dlt[i] = z-ps[i];
    f += s * (s-1) / 2;
  }
  for (int i=99998; i>=0; --i) {
    dlt[i] = min(dlt[i], dlt[i+1]);
  }
  k = 0;
  for (int i=0; i<100000; ++i) {
    if (dlt[i] > k) {
      ++k;
      f -= min(n-cnt[i], l)-1;
    }
  }
  cout << f << '\n';
}
# Verdict Execution time Memory Grader output
1 Correct 2 ms 2652 KB Output is correct
2 Correct 2 ms 2648 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 2652 KB Output is correct
2 Correct 2 ms 2776 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 2652 KB Output is correct
2 Correct 2 ms 2652 KB Output is correct
# Verdict Execution time Memory Grader output
1 Incorrect 2 ms 2652 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 3 ms 2652 KB Output is correct
2 Correct 3 ms 2804 KB Output is correct
# Verdict Execution time Memory Grader output
1 Incorrect 5 ms 2652 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 14 ms 2652 KB Output is correct
# Verdict Execution time Memory Grader output
1 Incorrect 21 ms 2652 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 42 ms 2548 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 48 ms 2648 KB Output is correct
2 Correct 31 ms 2644 KB Output is correct
# Verdict Execution time Memory Grader output
1 Incorrect 56 ms 2688 KB Output isn't correct
2 Halted 0 ms 0 KB -