Submission #204534

# Submission time Handle Problem Language Result Execution time Memory
204534 2020-02-26T09:03:14 Z WLZ Divide and conquer (IZhO14_divide) C++14
100 / 100
59 ms 5996 KB
#include <bits/stdc++.h>
using namespace std;

int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  int n;
  cin >> n;
  vector<long long> x(n + 1), g(n + 1, 0), d(n + 1, 0);
  vector< pair<long long, int> > v;
  for (int i = 1; i <= n; i++) {
    cin >> x[i] >> g[i] >> d[i];
    g[i] += g[i - 1];
    d[i] += d[i - 1];
    v.push_back({d[i] - x[i], i});
  }
  sort(v.begin(), v.end());
  vector<long long> a(n), mx(n);
  for (int i = 0; i < n; i++) {
    a[i] = v[i].first;
  }
  for (int i = n - 1; i >= 0; i--) {
    mx[i] = g[v[i].second];
    if (i < n - 1) {
      mx[i] = max(mx[i], mx[i + 1]);
    }
  }
  long long ans = 0;
  for (int i = 1; i <= n; i++) {
    int j = lower_bound(a.begin(), a.end(), d[i - 1] - x[i]) - a.begin();
    ans = max(ans, mx[j] - g[i - 1]);
  }
  cout << ans << '\n';
  return 0;
}
# Verdict Execution time Memory Grader output
1 Correct 5 ms 376 KB Output is correct
2 Correct 5 ms 376 KB Output is correct
3 Correct 5 ms 376 KB Output is correct
4 Correct 5 ms 376 KB Output is correct
5 Correct 5 ms 376 KB Output is correct
6 Correct 5 ms 376 KB Output is correct
7 Correct 5 ms 376 KB Output is correct
8 Correct 5 ms 376 KB Output is correct
9 Correct 5 ms 380 KB Output is correct
10 Correct 5 ms 376 KB Output is correct
11 Correct 5 ms 376 KB Output is correct
12 Correct 5 ms 376 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 5 ms 380 KB Output is correct
2 Correct 5 ms 376 KB Output is correct
3 Correct 5 ms 376 KB Output is correct
4 Correct 5 ms 376 KB Output is correct
5 Correct 5 ms 376 KB Output is correct
6 Correct 5 ms 376 KB Output is correct
7 Correct 5 ms 376 KB Output is correct
8 Correct 5 ms 376 KB Output is correct
9 Correct 5 ms 376 KB Output is correct
10 Correct 5 ms 376 KB Output is correct
11 Correct 7 ms 632 KB Output is correct
12 Correct 7 ms 632 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 7 ms 632 KB Output is correct
2 Correct 8 ms 1016 KB Output is correct
3 Correct 10 ms 1016 KB Output is correct
4 Correct 27 ms 3056 KB Output is correct
5 Correct 30 ms 3056 KB Output is correct
6 Correct 59 ms 5868 KB Output is correct
7 Correct 53 ms 5872 KB Output is correct
8 Correct 50 ms 5868 KB Output is correct
9 Correct 47 ms 5868 KB Output is correct
10 Correct 58 ms 5848 KB Output is correct
11 Correct 53 ms 5868 KB Output is correct
12 Correct 55 ms 5996 KB Output is correct