Submission #245329

# Submission time Handle Problem Language Result Execution time Memory
245329 2020-07-06T04:12:51 Z kshitij_sodani Divide and conquer (IZhO14_divide) C++17
0 / 100
5 ms 384 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,low);
			}
		}
		/*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 384 KB Output is correct
2 Incorrect 5 ms 384 KB Output isn't correct
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 5 ms 384 KB Output is correct
2 Incorrect 5 ms 384 KB Output isn't correct
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 5 ms 384 KB Output is correct
2 Incorrect 5 ms 384 KB Output isn't correct
3 Halted 0 ms 0 KB -