Submission #245330

# Submission time Handle Problem Language Result Execution time Memory
245330 2020-07-06T04:13:35 Z kshitij_sodani Divide and conquer (IZhO14_divide) C++17
100 / 100
53 ms 7396 KB
#include <bits/stdc++.h>
using namespace std;
typedef int64_t llo;
#define mp make_pair
#define pb push_back
#define a first 
#define b second
//#define endl '\n'
llo n;
llo aa[100000];
llo bb[100000];
llo cc[100000];
int main(){
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	cin>>n;
	vector<llo> arr;
	llo su=0;
	llo ans=0;
	vector<llo> pre;
	for(llo i=0;i<n;i++){

		cin>>aa[i]>>bb[i]>>cc[i];
		llo cur=aa[i]-su-cc[i];
		llo low=0;
		llo high=i-1;
		while(low<high-1){
			llo mid=(low+high)/2;
			if(arr[mid]>=cur){
				high=mid;
			}
			else{
				low=mid;
			}
		}
		llo ind=i;
		for(llo j=low;j<high+1;j++){
			if(arr[j]>=cur){
				ind=min(ind,j);
			}
		}
		/*for(auto j:arr){
			cout<<j<<",";
		}
		cout<<endl;*/
		if(pre.size()){
			pre.pb(pre.back()+bb[i]);
		}
		else{
			pre.pb(bb[i]);
		}
		if(ind==0){
			ans=max(ans,pre[i]);
		}
		else{
			ans=max(ans,pre[i]-pre[ind-1]);
		}
		if(arr.size()){
			arr.pb(max(arr.back(),aa[i]-su));
		}
		else{
			arr.pb(aa[i]);
		}
		su+=cc[i];
	}
	cout<<ans<<endl;
	






	return 0;
}
# Verdict Execution time Memory Grader output
1 Correct 5 ms 256 KB Output is correct
2 Correct 4 ms 384 KB Output is correct
3 Correct 5 ms 384 KB Output is correct
4 Correct 5 ms 384 KB Output is correct
5 Correct 5 ms 384 KB Output is correct
6 Correct 5 ms 384 KB Output is correct
7 Correct 5 ms 384 KB Output is correct
8 Correct 5 ms 384 KB Output is correct
9 Correct 5 ms 384 KB Output is correct
10 Correct 5 ms 384 KB Output is correct
11 Correct 5 ms 384 KB Output is correct
12 Correct 5 ms 384 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 5 ms 256 KB Output is correct
2 Correct 4 ms 384 KB Output is correct
3 Correct 5 ms 384 KB Output is correct
4 Correct 5 ms 384 KB Output is correct
5 Correct 5 ms 384 KB Output is correct
6 Correct 5 ms 384 KB Output is correct
7 Correct 5 ms 384 KB Output is correct
8 Correct 5 ms 384 KB Output is correct
9 Correct 5 ms 384 KB Output is correct
10 Correct 5 ms 384 KB Output is correct
11 Correct 5 ms 384 KB Output is correct
12 Correct 5 ms 384 KB Output is correct
13 Correct 4 ms 384 KB Output is correct
14 Correct 5 ms 408 KB Output is correct
15 Correct 5 ms 384 KB Output is correct
16 Correct 5 ms 384 KB Output is correct
17 Correct 5 ms 384 KB Output is correct
18 Correct 5 ms 512 KB Output is correct
19 Correct 5 ms 384 KB Output is correct
20 Correct 5 ms 384 KB Output is correct
21 Correct 5 ms 512 KB Output is correct
22 Correct 5 ms 512 KB Output is correct
23 Correct 7 ms 768 KB Output is correct
24 Correct 7 ms 768 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 5 ms 256 KB Output is correct
2 Correct 4 ms 384 KB Output is correct
3 Correct 5 ms 384 KB Output is correct
4 Correct 5 ms 384 KB Output is correct
5 Correct 5 ms 384 KB Output is correct
6 Correct 5 ms 384 KB Output is correct
7 Correct 5 ms 384 KB Output is correct
8 Correct 5 ms 384 KB Output is correct
9 Correct 5 ms 384 KB Output is correct
10 Correct 5 ms 384 KB Output is correct
11 Correct 5 ms 384 KB Output is correct
12 Correct 5 ms 384 KB Output is correct
13 Correct 4 ms 384 KB Output is correct
14 Correct 5 ms 408 KB Output is correct
15 Correct 5 ms 384 KB Output is correct
16 Correct 5 ms 384 KB Output is correct
17 Correct 5 ms 384 KB Output is correct
18 Correct 5 ms 512 KB Output is correct
19 Correct 5 ms 384 KB Output is correct
20 Correct 5 ms 384 KB Output is correct
21 Correct 5 ms 512 KB Output is correct
22 Correct 5 ms 512 KB Output is correct
23 Correct 7 ms 768 KB Output is correct
24 Correct 7 ms 768 KB Output is correct
25 Correct 6 ms 640 KB Output is correct
26 Correct 8 ms 1024 KB Output is correct
27 Correct 9 ms 1152 KB Output is correct
28 Correct 25 ms 3572 KB Output is correct
29 Correct 28 ms 3820 KB Output is correct
30 Correct 53 ms 7396 KB Output is correct
31 Correct 44 ms 6244 KB Output is correct
32 Correct 42 ms 6244 KB Output is correct
33 Correct 45 ms 6112 KB Output is correct
34 Correct 47 ms 6116 KB Output is correct
35 Correct 46 ms 6628 KB Output is correct
36 Correct 50 ms 6756 KB Output is correct