Submission #632222

# Submission time Handle Problem Language Result Execution time Memory
632222 2022-08-19T16:33:32 Z Jovan26 Fountain (eJOI20_fountain) C++14
60 / 100
321 ms 5192 KB
#include<iostream>
using namespace std;
int d[100005];
int c[100005];
int ci[100005];
bool check(int r,int v,int x){
	if(ci[x]-ci[r]<v) return true;
	return false;
}
int main(){
	int n,q;
	cin>>n>>q;
	for(int i=1;i<n+1;i++) cin>>d[i]>>c[i];
	ci[1] = 0;
	for(int i=2;i<=n;i++){
		ci[i] = c[i-1]+ci[i-1];
	}
	ci[0] = ci[n]+c[n];
	if(n<1005){
		int p;
	for(int i=0;i<q;i++){
		int r,v;
		cin>>r>>v;
		p=0;
		for(int j=r;j<=n;j++){
			if(d[j]>p){
				v-=c[j];
				p=d[j];
			}
				if(v<=0) {
				cout<<j<<endl;
				break;
		}
		if(j==n){
			cout<<0<<endl;
			break;
		}
			}
		}
	}
	else{
	for(int e = 0;e<q;e++){
		int r,v;
		cin>>r>>v;
		if(ci[0]-ci[r]<v) cout<<0<<endl;
		else{
			int l = r;
			int r1 = n;
			int cr;
			while(r1>=l){
				int mid = (r1+l)/2;
				if((r1+l)%2==1) mid++;	
				if(check(r,v,mid)){
					l = mid+1;
					cr = mid;
				}
				else{
					r1 = mid-1;
				}
			}
		cout<<cr<<endl;	
		}
}
}
}

Compilation message

fountain.cpp: In function 'int main()':
fountain.cpp:61:9: warning: 'cr' may be used uninitialized in this function [-Wmaybe-uninitialized]
   61 |   cout<<cr<<endl;
      |         ^~
# Verdict Execution time Memory Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 2 ms 212 KB Output is correct
3 Correct 2 ms 340 KB Output is correct
4 Correct 4 ms 316 KB Output is correct
5 Correct 4 ms 340 KB Output is correct
6 Correct 5 ms 340 KB Output is correct
7 Correct 4 ms 340 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 289 ms 2256 KB Output is correct
2 Correct 321 ms 5192 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 2 ms 212 KB Output is correct
3 Correct 2 ms 340 KB Output is correct
4 Correct 4 ms 316 KB Output is correct
5 Correct 4 ms 340 KB Output is correct
6 Correct 5 ms 340 KB Output is correct
7 Correct 4 ms 340 KB Output is correct
8 Correct 289 ms 2256 KB Output is correct
9 Correct 321 ms 5192 KB Output is correct
10 Correct 4 ms 340 KB Output is correct
11 Incorrect 196 ms 3320 KB Output isn't correct
12 Halted 0 ms 0 KB -