답안 #402027

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
402027 2021-05-11T08:13:57 Z keta_tsimakuridze 금 캐기 (IZhO14_divide) C++14
100 / 100
839 ms 9208 KB
#include<bits/stdc++.h>
#define f first
#define int long long
#define s second
using namespace std;
const int N=2e5+5,mod=1e9+7,Inf=1e16;
int t,x[N],tree[4*N],d[N],g[N],pref[N],p[N],n;
string s;
int getans(int u,int start,int end,int l,int r){
	if(l>end || r<start) return -Inf;
	if(start<=l && r<=end) return tree[u];
	int mid=(l+r)/2;
	return max(getans(2*u,start,end,l,mid),getans(2*u+1,start,end,mid+1,r));
}
void build(int u,int l,int r){
	if(l==r) {
		tree[u] = +x[l+1]-pref[l];
		return;
	}
	int mid=(l+r)/2;
	build(2*u,l,mid);
	build(2*u+1,mid+1,r);
	tree[u] = max(tree[2*u],tree[2*u+1]);
}
bool check(int g){
	int l = 0;
	for(int i=1;i<=n;i++){
		while(l<i && p[i]-p[l]>=g) l++;
		// x[r]-x[l]+b[r] - b[l-1]  >=
		if(l==1 && pref[i]-x[i]+x[1] >= 0) return 1;
		if(getans(1,1,l-1,1,n) - x[i] + pref[i]>=0) {
		 return 1;}
	}
	return 0;
}
 main(){
	// t=1;
	cin>>n;
	for(int i=1;i<=n;i++){
		cin>>x[i]>>g[i]>>d[i];
	}
	int l=1,r=1e15,ans=0;
	sort(p+1,p+n+1);
	for(int i=1;i<=n;i++){
		pref[i] = pref[i-1] + d[i];
		p[i] = p[i-1] + g[i];
	}
	build(1,1,n);
	while(l<=r){
		int mid=(l+r)/2,L=0;
		if(check(mid)){
			ans=mid;
			l=mid+1;
		}
		else r=mid-1;
	}
	cout<<ans;
}

Compilation message

divide.cpp:36:2: warning: ISO C++ forbids declaration of 'main' with no type [-Wreturn-type]
   36 |  main(){
      |  ^~~~
divide.cpp: In function 'int main()':
divide.cpp:50:19: warning: unused variable 'L' [-Wunused-variable]
   50 |   int mid=(l+r)/2,L=0;
      |                   ^
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 296 KB Output is correct
2 Correct 1 ms 332 KB Output is correct
3 Correct 1 ms 332 KB Output is correct
4 Correct 1 ms 332 KB Output is correct
5 Correct 1 ms 332 KB Output is correct
6 Correct 2 ms 296 KB Output is correct
7 Correct 1 ms 332 KB Output is correct
8 Correct 1 ms 304 KB Output is correct
9 Correct 1 ms 332 KB Output is correct
10 Correct 1 ms 332 KB Output is correct
11 Correct 1 ms 332 KB Output is correct
12 Correct 1 ms 332 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 296 KB Output is correct
2 Correct 1 ms 332 KB Output is correct
3 Correct 1 ms 332 KB Output is correct
4 Correct 1 ms 332 KB Output is correct
5 Correct 1 ms 332 KB Output is correct
6 Correct 2 ms 296 KB Output is correct
7 Correct 1 ms 332 KB Output is correct
8 Correct 1 ms 304 KB Output is correct
9 Correct 1 ms 332 KB Output is correct
10 Correct 1 ms 332 KB Output is correct
11 Correct 1 ms 332 KB Output is correct
12 Correct 1 ms 332 KB Output is correct
13 Correct 1 ms 332 KB Output is correct
14 Correct 1 ms 332 KB Output is correct
15 Correct 2 ms 332 KB Output is correct
16 Correct 2 ms 312 KB Output is correct
17 Correct 5 ms 332 KB Output is correct
18 Correct 3 ms 332 KB Output is correct
19 Correct 3 ms 312 KB Output is correct
20 Correct 3 ms 308 KB Output is correct
21 Correct 4 ms 332 KB Output is correct
22 Correct 7 ms 460 KB Output is correct
23 Correct 24 ms 764 KB Output is correct
24 Correct 28 ms 716 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 296 KB Output is correct
2 Correct 1 ms 332 KB Output is correct
3 Correct 1 ms 332 KB Output is correct
4 Correct 1 ms 332 KB Output is correct
5 Correct 1 ms 332 KB Output is correct
6 Correct 2 ms 296 KB Output is correct
7 Correct 1 ms 332 KB Output is correct
8 Correct 1 ms 304 KB Output is correct
9 Correct 1 ms 332 KB Output is correct
10 Correct 1 ms 332 KB Output is correct
11 Correct 1 ms 332 KB Output is correct
12 Correct 1 ms 332 KB Output is correct
13 Correct 1 ms 332 KB Output is correct
14 Correct 1 ms 332 KB Output is correct
15 Correct 2 ms 332 KB Output is correct
16 Correct 2 ms 312 KB Output is correct
17 Correct 5 ms 332 KB Output is correct
18 Correct 3 ms 332 KB Output is correct
19 Correct 3 ms 312 KB Output is correct
20 Correct 3 ms 308 KB Output is correct
21 Correct 4 ms 332 KB Output is correct
22 Correct 7 ms 460 KB Output is correct
23 Correct 24 ms 764 KB Output is correct
24 Correct 28 ms 716 KB Output is correct
25 Correct 5 ms 716 KB Output is correct
26 Correct 10 ms 976 KB Output is correct
27 Correct 13 ms 1100 KB Output is correct
28 Correct 61 ms 4296 KB Output is correct
29 Correct 72 ms 4724 KB Output is correct
30 Correct 149 ms 9208 KB Output is correct
31 Correct 114 ms 7980 KB Output is correct
32 Correct 147 ms 7980 KB Output is correct
33 Correct 109 ms 7788 KB Output is correct
34 Correct 565 ms 7980 KB Output is correct
35 Correct 839 ms 8388 KB Output is correct
36 Correct 808 ms 8580 KB Output is correct