Submission #344724

# Submission time Handle Problem Language Result Execution time Memory
344724 2021-01-06T10:48:28 Z mansur Divide and conquer (IZhO14_divide) C++14
100 / 100
46 ms 12268 KB
#include<bits/stdc++.h>
using namespace std;
 
#define all(a) a.begin(),a.end()
#define ll long long
#define pb push_back
#define nl '\n'
#define popb pop_back()
#define sz size()
#define ld long double
#define ull unsigned long long
#define F first
#define S second
#define fix fixed<<setprecision
#define pii pair<int,int>
#define E exit (0)
#define int long long
const int inf=1e9;
int x[100001],g[100001],d[100001],p[100001],pp[100001];
vector<pii>t(400001);
void build(int u,int tl,int tr) {
	if (tl==tr) {
	 	t[u]={p[tl]-x[tl],tl};
	 	return;
	}	
	int mid=(tl+tr)/2;
	build(u*2,tl,mid);
	build(u*2+1,mid+1,tr);
	if (t[u*2].F>t[u*2+1].F) {
		t[u]=t[u*2];
	}else {
		t[u]=t[u*2+1];	
	}
}
int get(int u,int tl,int tr,int l,int r,int x) {
	if (tl==tr) {
		return tl;
	}
	int mid=(tl+tr)/2;
	if (t[u*2+1].F>=x) {
		return get(u*2+1,mid+1,tr,l,r,x);
	}
	return get(u*2,tl,mid,l,r,x);
}
signed main() {
	//freopen("planting.in","r",stdin);
	//freopen("planting.out","w",stdout);
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	int n;
	cin>>n;
	for (int i=1;i<=n;i++) {
		cin>>x[i]>>g[i]>>d[i];
		p[i]=p[i-1]+d[i];
		pp[i]=pp[i-1]+g[i];
	}
	build(1,1,n);
	int mx=0;
	for (int i=1;i<=n;i++) {
		int z=p[i-1]-x[i];
		mx=max(mx,pp[get(1,1,n,i,n,z)]-pp[i-1]);	
	}
	cout<<mx;
}
# Verdict Execution time Memory Grader output
1 Correct 4 ms 6768 KB Output is correct
2 Correct 5 ms 6636 KB Output is correct
3 Correct 4 ms 6636 KB Output is correct
4 Correct 4 ms 6636 KB Output is correct
5 Correct 4 ms 6636 KB Output is correct
6 Correct 4 ms 6636 KB Output is correct
7 Correct 4 ms 6636 KB Output is correct
8 Correct 5 ms 6636 KB Output is correct
9 Correct 4 ms 6636 KB Output is correct
10 Correct 4 ms 6636 KB Output is correct
11 Correct 4 ms 6636 KB Output is correct
12 Correct 4 ms 6636 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 4 ms 6768 KB Output is correct
2 Correct 5 ms 6636 KB Output is correct
3 Correct 4 ms 6636 KB Output is correct
4 Correct 4 ms 6636 KB Output is correct
5 Correct 4 ms 6636 KB Output is correct
6 Correct 4 ms 6636 KB Output is correct
7 Correct 4 ms 6636 KB Output is correct
8 Correct 5 ms 6636 KB Output is correct
9 Correct 4 ms 6636 KB Output is correct
10 Correct 4 ms 6636 KB Output is correct
11 Correct 4 ms 6636 KB Output is correct
12 Correct 4 ms 6636 KB Output is correct
13 Correct 4 ms 6636 KB Output is correct
14 Correct 4 ms 6636 KB Output is correct
15 Correct 4 ms 6636 KB Output is correct
16 Correct 4 ms 6636 KB Output is correct
17 Correct 4 ms 6636 KB Output is correct
18 Correct 6 ms 6636 KB Output is correct
19 Correct 4 ms 6636 KB Output is correct
20 Correct 5 ms 6636 KB Output is correct
21 Correct 5 ms 6636 KB Output is correct
22 Correct 6 ms 6636 KB Output is correct
23 Correct 6 ms 6764 KB Output is correct
24 Correct 6 ms 6764 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 4 ms 6768 KB Output is correct
2 Correct 5 ms 6636 KB Output is correct
3 Correct 4 ms 6636 KB Output is correct
4 Correct 4 ms 6636 KB Output is correct
5 Correct 4 ms 6636 KB Output is correct
6 Correct 4 ms 6636 KB Output is correct
7 Correct 4 ms 6636 KB Output is correct
8 Correct 5 ms 6636 KB Output is correct
9 Correct 4 ms 6636 KB Output is correct
10 Correct 4 ms 6636 KB Output is correct
11 Correct 4 ms 6636 KB Output is correct
12 Correct 4 ms 6636 KB Output is correct
13 Correct 4 ms 6636 KB Output is correct
14 Correct 4 ms 6636 KB Output is correct
15 Correct 4 ms 6636 KB Output is correct
16 Correct 4 ms 6636 KB Output is correct
17 Correct 4 ms 6636 KB Output is correct
18 Correct 6 ms 6636 KB Output is correct
19 Correct 4 ms 6636 KB Output is correct
20 Correct 5 ms 6636 KB Output is correct
21 Correct 5 ms 6636 KB Output is correct
22 Correct 6 ms 6636 KB Output is correct
23 Correct 6 ms 6764 KB Output is correct
24 Correct 6 ms 6764 KB Output is correct
25 Correct 5 ms 6764 KB Output is correct
26 Correct 7 ms 7020 KB Output is correct
27 Correct 8 ms 7020 KB Output is correct
28 Correct 22 ms 8556 KB Output is correct
29 Correct 25 ms 9836 KB Output is correct
30 Correct 45 ms 12140 KB Output is correct
31 Correct 39 ms 12160 KB Output is correct
32 Correct 40 ms 12268 KB Output is correct
33 Correct 39 ms 12140 KB Output is correct
34 Correct 44 ms 12268 KB Output is correct
35 Correct 41 ms 12140 KB Output is correct
36 Correct 46 ms 12140 KB Output is correct