Submission #337628

# Submission time Handle Problem Language Result Execution time Memory
337628 2020-12-21T09:47:15 Z kutbilim_one Divide and conquer (IZhO14_divide) C++14
100 / 100
39 ms 6924 KB
#include <bits/stdc++.h>
 
using namespace std;
 
#define endl '\n'
#define all(x) x.begin(),x.end()
#define int long long

const int 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)>>1;
     	if(mn[m] <= E) r = m;
      	else l = m+1;
   	}
  	return r;
}
 
signed main(){
   	ios_base::sync_with_stdio(false);
   	cin.tie(nullptr);
   
   	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] + prg[i-1];
     	prd[i] = d[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 << endl;
   
	return 0;
}

Compilation message

divide.cpp: In function 'long long int search(long long int, long long int)':
divide.cpp:15:23: warning: unused variable 'pos' [-Wunused-variable]
   15 |     int l = 1, r = i, pos = 1;
      |                       ^~~
# Verdict Execution time Memory Grader output
1 Correct 1 ms 364 KB Output is correct
2 Correct 0 ms 364 KB Output is correct
3 Correct 1 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 364 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 364 KB Output is correct
2 Correct 0 ms 364 KB Output is correct
3 Correct 1 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 364 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 492 KB Output is correct
18 Correct 1 ms 492 KB Output is correct
19 Correct 1 ms 492 KB Output is correct
20 Correct 1 ms 492 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 748 KB Output is correct
24 Correct 2 ms 748 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 364 KB Output is correct
2 Correct 0 ms 364 KB Output is correct
3 Correct 1 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 364 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 492 KB Output is correct
18 Correct 1 ms 492 KB Output is correct
19 Correct 1 ms 492 KB Output is correct
20 Correct 1 ms 492 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 748 KB Output is correct
24 Correct 2 ms 748 KB Output is correct
25 Correct 2 ms 620 KB Output is correct
26 Correct 3 ms 908 KB Output is correct
27 Correct 4 ms 1004 KB Output is correct
28 Correct 17 ms 3764 KB Output is correct
29 Correct 19 ms 4076 KB Output is correct
30 Correct 39 ms 6764 KB Output is correct
31 Correct 32 ms 6764 KB Output is correct
32 Correct 32 ms 6764 KB Output is correct
33 Correct 31 ms 6636 KB Output is correct
34 Correct 35 ms 6636 KB Output is correct
35 Correct 36 ms 6924 KB Output is correct
36 Correct 36 ms 6764 KB Output is correct