Submission #89901

# Submission time Handle Problem Language Result Execution time Memory
89901 2018-12-19T00:15:03 Z xiaowuc1 Art Exhibition (JOI18_art) C++14
0 / 100
2 ms 376 KB
#include <bits/stdc++.h>

using namespace std;

typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;

pll l[500000];
int n;

ll solve(int amt) {
  ll ret = 0;
  ll sum = 0;
  for(int i = 0; i < n; i++) {
    sum += l[i].second;
    if(i >= amt) {
      sum -= l[i-amt].second;
    }
    if(i >= amt-1) {
      ret = max(ret, sum - (l[i].first - l[i-amt+1].first));
    }
  }
  return ret;
}

void solve() {
  cin >> n;
  for(int i = 0; i < n; i++) {
    cin >> l[i].first >> l[i].second;
  }
  sort(l, l+n);
  ll lhs = 1;
  ll rhs = n;
  ll ret = 0;
  while(lhs != rhs) {
    ll m1 = (lhs+rhs)/2;
    ll m2 = m1+1;
    ll a1 = solve(m1);
    ll a2 = solve(m2);
    if(a1 > a2) {
      ret = max(ret, a1);
      rhs = m2-1;
    }
    else {
      ret = max(ret, a2);
      lhs = m1+1;
    }
  }
  cout << ret << endl;
}

int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie(NULL);
  solve();
}
# Verdict Execution time Memory Grader output
1 Incorrect 2 ms 376 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 2 ms 376 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 2 ms 376 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 2 ms 376 KB Output isn't correct
2 Halted 0 ms 0 KB -