Submission #338986

# Submission time Handle Problem Language Result Execution time Memory
338986 2020-12-24T10:47:15 Z katearima Divide and conquer (IZhO14_divide) C++14
100 / 100
276 ms 19420 KB
#include <bits/stdc++.h>
#define ll long long
#define val first
#define ind second
using namespace std;
const int N=1e5+5;
int n,a,b,x;
ll ans;
typedef struct{
	int x, gold , energy;
}camp;
vector<camp> v;
vector<pair<ll, int>> mn;
map <int, ll> g, d;
main(){
	cin>>n;
	for(int i=0; i<n; i++){
		cin>>x>>a>>b;
		v.push_back({x,a,b});
	}
	g[0]=v[0].gold; d[0]=v[0].energy;
	for(int i=1; i<n; i++){
		g[i]=g[i-1]+v[i].gold;
		d[i]=d[i-1]+v[i].energy;
	}
	a=0;
	for(int i=0; i<n; i++){
		b=i; int mid=0;
		
		if(mn.size()==0 || mn[mn.size()-1].val>d[b-1]-v[b].x){
			mn.push_back({d[b-1]-v[b].x,i}); 
		}
		int cost=d[b]-v[b].x;
		int l=0; int r=mn.size()-1;
		while(l<=r){
			mid=(l+r)/2;
			if(mn[mid].val<=cost) {
				r=mid-1;
				a=mn[mid].ind;
			}
			else l=mid+1;
		}
		//a=mn[mid].ind;
		ans=max(ans, g[b]-g[a-1]);
		//cout<<a<<" "<<b<<" "<<mid<<" "<<mn[mid].val<<" "<<g[b]-g[a-1]<<endl;	
	}
	cout<<ans<<endl;
}

/*
x2-x1 <= d[e2]-d[e1-1]
d[e2]-x2 >= kiki sworia swoooooooria aia    aa a  a 
*/

Compilation message

divide.cpp:15:6: warning: ISO C++ forbids declaration of 'main' with no type [-Wreturn-type]
   15 | main(){
      |      ^
# Verdict Execution time Memory Grader output
1 Correct 1 ms 364 KB Output is correct
2 Correct 1 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 1 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 2 ms 492 KB Output is correct
17 Correct 2 ms 492 KB Output is correct
18 Correct 3 ms 492 KB Output is correct
19 Correct 2 ms 492 KB Output is correct
20 Correct 2 ms 512 KB Output is correct
21 Correct 3 ms 620 KB Output is correct
22 Correct 4 ms 620 KB Output is correct
23 Correct 10 ms 1260 KB Output is correct
24 Correct 12 ms 1388 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 364 KB Output is correct
2 Correct 1 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 2 ms 492 KB Output is correct
17 Correct 2 ms 492 KB Output is correct
18 Correct 3 ms 492 KB Output is correct
19 Correct 2 ms 492 KB Output is correct
20 Correct 2 ms 512 KB Output is correct
21 Correct 3 ms 620 KB Output is correct
22 Correct 4 ms 620 KB Output is correct
23 Correct 10 ms 1260 KB Output is correct
24 Correct 12 ms 1388 KB Output is correct
25 Correct 8 ms 1004 KB Output is correct
26 Correct 15 ms 1836 KB Output is correct
27 Correct 17 ms 1836 KB Output is correct
28 Correct 103 ms 8160 KB Output is correct
29 Correct 116 ms 8464 KB Output is correct
30 Correct 243 ms 16860 KB Output is correct
31 Correct 206 ms 15708 KB Output is correct
32 Correct 221 ms 15964 KB Output is correct
33 Correct 215 ms 15708 KB Output is correct
34 Correct 217 ms 17500 KB Output is correct
35 Correct 276 ms 19292 KB Output is correct
36 Correct 245 ms 19420 KB Output is correct