Submission #529583

# Submission time Handle Problem Language Result Execution time Memory
529583 2022-02-23T08:35:42 Z Kenjikrab Divide and conquer (IZhO14_divide) C++14
0 / 100
1 ms 296 KB
#include<bits/stdc++.h>
#define ll long long
#define db double
#define pb push_back
#define pii pair<int,int>
#define fi first
#define se second
#define loop(i,j,k) for(int i=j;i<k;i++)
using namespace std;
signed main(){
	//ios_base::sync_with_stdio(false);cin.tie(0);
	int n;
	cin>>n;
	int ans=0;
	vector<int> x,g,p;
	x.pb(0);
	g.pb(0);
	p.pb(0);
	for(int i=0;i<n;i++){
		int a,b,c;
		cin>>a>>b>>c;
		x.pb(a);
		g.pb(g[i]+b);
		p.pb(p[i]+c);
	}
	vector<pii> diff;
	ans=g[n]-g[n-1];
	diff.pb({x[n]-p[n],g[n]});
	for(int i=n-1;i>0;i--){
		if(x[i]-p[i]<diff.back().fi) diff.pb({x[i]-p[i],g[i]});
		int con=x[i]-p[i-1];
		int l=0,r=diff.size()-1;
		while(r<l){
			int mid=(l+r)/2;
			if(diff[mid].fi>con) r=mid+1;
			else l=mid;
		}
		if(diff[l].fi<=con) ans=max(ans,diff[l].se-g[i-1]);
		else ans=max(ans,g[i]-g[i-1]);
	}
	cout<<ans;
	return 0;
}
# Verdict Execution time Memory Grader output
1 Correct 1 ms 296 KB Output is correct
2 Correct 1 ms 204 KB Output is correct
3 Correct 0 ms 204 KB Output is correct
4 Correct 1 ms 204 KB Output is correct
5 Correct 0 ms 204 KB Output is correct
6 Incorrect 1 ms 204 KB Output isn't correct
7 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 296 KB Output is correct
2 Correct 1 ms 204 KB Output is correct
3 Correct 0 ms 204 KB Output is correct
4 Correct 1 ms 204 KB Output is correct
5 Correct 0 ms 204 KB Output is correct
6 Incorrect 1 ms 204 KB Output isn't correct
7 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 296 KB Output is correct
2 Correct 1 ms 204 KB Output is correct
3 Correct 0 ms 204 KB Output is correct
4 Correct 1 ms 204 KB Output is correct
5 Correct 0 ms 204 KB Output is correct
6 Incorrect 1 ms 204 KB Output isn't correct
7 Halted 0 ms 0 KB -