Submission #1018041

# Submission time Handle Problem Language Result Execution time Memory
1018041 2024-07-09T13:11:32 Z ind1v Divide and conquer (IZhO14_divide) C++11
100 / 100
38 ms 9476 KB
#include <bits/stdc++.h>

using namespace std;

const int N = 1e5 + 5;

int n;
int x[N], g[N], d[N];
long long pd[N], pg[N];

int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  cin >> n;
  vector<pair<long long, int>> v1, v2;
  for (int i = 1; i <= n; i++) {
    cin >> x[i] >> g[i] >> d[i];
    pd[i] = d[i] + pd[i - 1];
    pg[i] = g[i] + pg[i - 1];
    v1.emplace_back(x[i] - pd[i], i);
    v2.emplace_back(x[i] - pd[i - 1], i);
  }
  sort(v1.begin(), v1.end(), greater<pair<long long, int>>());
  sort(v2.begin(), v2.end(), greater<pair<long long, int>>());
  int mn = 1e9;
  long long ans = -1e9;
  for (int i = 0, j = 0; i < v1.size(); i++) {
    while (j < v2.size() && v2[j].first >= v1[i].first) {
      mn = min(mn, v2[j++].second);
    }
    if (mn != 1e9) {
      ans = max(ans, pg[v1[i].second] - pg[mn - 1]);
    }
  }
  cout << ans << '\n';
  return 0;
}

Compilation message

divide.cpp: In function 'int main()':
divide.cpp:27:28: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::pair<long long int, int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   27 |   for (int i = 0, j = 0; i < v1.size(); i++) {
      |                          ~~^~~~~~~~~~~
divide.cpp:28:14: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::pair<long long int, int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   28 |     while (j < v2.size() && v2[j].first >= v1[i].first) {
      |            ~~^~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 0 ms 2396 KB Output is correct
2 Correct 1 ms 2396 KB Output is correct
3 Correct 0 ms 2396 KB Output is correct
4 Correct 0 ms 2396 KB Output is correct
5 Correct 1 ms 2396 KB Output is correct
6 Correct 1 ms 2392 KB Output is correct
7 Correct 1 ms 2396 KB Output is correct
8 Correct 0 ms 2396 KB Output is correct
9 Correct 1 ms 2396 KB Output is correct
10 Correct 0 ms 2396 KB Output is correct
11 Correct 1 ms 2396 KB Output is correct
12 Correct 1 ms 2392 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 2396 KB Output is correct
2 Correct 1 ms 2396 KB Output is correct
3 Correct 0 ms 2396 KB Output is correct
4 Correct 0 ms 2396 KB Output is correct
5 Correct 1 ms 2396 KB Output is correct
6 Correct 1 ms 2392 KB Output is correct
7 Correct 1 ms 2396 KB Output is correct
8 Correct 0 ms 2396 KB Output is correct
9 Correct 1 ms 2396 KB Output is correct
10 Correct 0 ms 2396 KB Output is correct
11 Correct 1 ms 2396 KB Output is correct
12 Correct 1 ms 2392 KB Output is correct
13 Correct 0 ms 2396 KB Output is correct
14 Correct 1 ms 2396 KB Output is correct
15 Correct 0 ms 2396 KB Output is correct
16 Correct 1 ms 2396 KB Output is correct
17 Correct 1 ms 2396 KB Output is correct
18 Correct 1 ms 2396 KB Output is correct
19 Correct 1 ms 2652 KB Output is correct
20 Correct 1 ms 2396 KB Output is correct
21 Correct 1 ms 2396 KB Output is correct
22 Correct 1 ms 2652 KB Output is correct
23 Correct 3 ms 2948 KB Output is correct
24 Correct 2 ms 2908 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 2396 KB Output is correct
2 Correct 1 ms 2396 KB Output is correct
3 Correct 0 ms 2396 KB Output is correct
4 Correct 0 ms 2396 KB Output is correct
5 Correct 1 ms 2396 KB Output is correct
6 Correct 1 ms 2392 KB Output is correct
7 Correct 1 ms 2396 KB Output is correct
8 Correct 0 ms 2396 KB Output is correct
9 Correct 1 ms 2396 KB Output is correct
10 Correct 0 ms 2396 KB Output is correct
11 Correct 1 ms 2396 KB Output is correct
12 Correct 1 ms 2392 KB Output is correct
13 Correct 0 ms 2396 KB Output is correct
14 Correct 1 ms 2396 KB Output is correct
15 Correct 0 ms 2396 KB Output is correct
16 Correct 1 ms 2396 KB Output is correct
17 Correct 1 ms 2396 KB Output is correct
18 Correct 1 ms 2396 KB Output is correct
19 Correct 1 ms 2652 KB Output is correct
20 Correct 1 ms 2396 KB Output is correct
21 Correct 1 ms 2396 KB Output is correct
22 Correct 1 ms 2652 KB Output is correct
23 Correct 3 ms 2948 KB Output is correct
24 Correct 2 ms 2908 KB Output is correct
25 Correct 2 ms 2908 KB Output is correct
26 Correct 3 ms 3112 KB Output is correct
27 Correct 3 ms 3336 KB Output is correct
28 Correct 12 ms 5576 KB Output is correct
29 Correct 13 ms 5864 KB Output is correct
30 Correct 26 ms 9476 KB Output is correct
31 Correct 32 ms 8380 KB Output is correct
32 Correct 23 ms 8384 KB Output is correct
33 Correct 38 ms 7996 KB Output is correct
34 Correct 23 ms 8128 KB Output is correct
35 Correct 26 ms 8640 KB Output is correct
36 Correct 22 ms 8808 KB Output is correct