Submission #337538

# Submission time Handle Problem Language Result Execution time Memory
337538 2020-12-21T04:24:55 Z boykut Divide and conquer (IZhO14_divide) C++14
100 / 100
37 ms 5100 KB
#include <bits/stdc++.h>

using namespace std;

#define int long long
#define MAXN 100100

int x[MAXN], g[MAXN], d[MAXN], n;
int prg[MAXN], prd[MAXN], mn[MAXN];
int ans;

int search(int i, int E) {
   int l = 1, r = i, pos = 1;
   while (l < r) {
      int m = (l + r) / 2;
      if (mn[m] <= E) {
         r = m;
      } else {
         l = m + 1;
      }
   }
   return r;
}

signed main() {
   ios::sync_with_stdio(0);
   cin.tie(0);
   
   cin >> n;
   
   for (int i = 1; i <= n; i++) {
      cin >> x[i] >> g[i] >> d[i];
   }
   
   mn[0] = 1e18;
   for (int i = 1; i <= n; i++) {
      prg[i] = g[i];
      prd[i] = d[i];
      prg[i] += prg[i - 1],
      prd[i] += prd[i - 1];
      mn[i] = min(mn[i - 1], prd[i - 1] - x[i]);
      
      int left = search(i, prd[i] - x[i]);
      ans = max(ans, prg[i] - prg[left - 1]);
   }
   
   cout << ans << '\n';
   
   return 0;
}

Compilation message

divide.cpp: In function 'long long int search(long long int, long long int)':
divide.cpp:13:22: warning: unused variable 'pos' [-Wunused-variable]
   13 |    int l = 1, r = i, pos = 1;
      |                      ^~~
# Verdict Execution time Memory Grader output
1 Correct 1 ms 364 KB Output is correct
2 Correct 1 ms 364 KB Output is correct
3 Correct 0 ms 364 KB Output is correct
4 Correct 1 ms 364 KB Output is correct
5 Correct 1 ms 364 KB Output is correct
6 Correct 1 ms 364 KB Output is correct
7 Correct 1 ms 364 KB Output is correct
8 Correct 1 ms 364 KB Output is correct
9 Correct 1 ms 364 KB Output is correct
10 Correct 1 ms 364 KB Output is correct
11 Correct 1 ms 364 KB Output is correct
12 Correct 1 ms 236 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 364 KB Output is correct
2 Correct 1 ms 364 KB Output is correct
3 Correct 0 ms 364 KB Output is correct
4 Correct 1 ms 364 KB Output is correct
5 Correct 1 ms 364 KB Output is correct
6 Correct 1 ms 364 KB Output is correct
7 Correct 1 ms 364 KB Output is correct
8 Correct 1 ms 364 KB Output is correct
9 Correct 1 ms 364 KB Output is correct
10 Correct 1 ms 364 KB Output is correct
11 Correct 1 ms 364 KB Output is correct
12 Correct 1 ms 236 KB Output is correct
13 Correct 1 ms 364 KB Output is correct
14 Correct 1 ms 364 KB Output is correct
15 Correct 1 ms 364 KB Output is correct
16 Correct 1 ms 364 KB Output is correct
17 Correct 1 ms 364 KB Output is correct
18 Correct 1 ms 364 KB Output is correct
19 Correct 1 ms 364 KB Output is correct
20 Correct 1 ms 384 KB Output is correct
21 Correct 1 ms 492 KB Output is correct
22 Correct 1 ms 492 KB Output is correct
23 Correct 2 ms 620 KB Output is correct
24 Correct 2 ms 620 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 364 KB Output is correct
2 Correct 1 ms 364 KB Output is correct
3 Correct 0 ms 364 KB Output is correct
4 Correct 1 ms 364 KB Output is correct
5 Correct 1 ms 364 KB Output is correct
6 Correct 1 ms 364 KB Output is correct
7 Correct 1 ms 364 KB Output is correct
8 Correct 1 ms 364 KB Output is correct
9 Correct 1 ms 364 KB Output is correct
10 Correct 1 ms 364 KB Output is correct
11 Correct 1 ms 364 KB Output is correct
12 Correct 1 ms 236 KB Output is correct
13 Correct 1 ms 364 KB Output is correct
14 Correct 1 ms 364 KB Output is correct
15 Correct 1 ms 364 KB Output is correct
16 Correct 1 ms 364 KB Output is correct
17 Correct 1 ms 364 KB Output is correct
18 Correct 1 ms 364 KB Output is correct
19 Correct 1 ms 364 KB Output is correct
20 Correct 1 ms 384 KB Output is correct
21 Correct 1 ms 492 KB Output is correct
22 Correct 1 ms 492 KB Output is correct
23 Correct 2 ms 620 KB Output is correct
24 Correct 2 ms 620 KB Output is correct
25 Correct 2 ms 620 KB Output is correct
26 Correct 3 ms 876 KB Output is correct
27 Correct 4 ms 876 KB Output is correct
28 Correct 16 ms 2668 KB Output is correct
29 Correct 18 ms 2668 KB Output is correct
30 Correct 37 ms 4972 KB Output is correct
31 Correct 33 ms 5100 KB Output is correct
32 Correct 33 ms 5100 KB Output is correct
33 Correct 31 ms 4972 KB Output is correct
34 Correct 32 ms 4972 KB Output is correct
35 Correct 33 ms 4972 KB Output is correct
36 Correct 35 ms 4972 KB Output is correct