Submission #620125

# Submission time Handle Problem Language Result Execution time Memory
620125 2022-08-03T01:02:32 Z Jovan26 Fountain (eJOI20_fountain) C++17
0 / 100
1500 ms 4940 KB
#include<iostream>
using namespace std;
int main(){
	ios_base::sync_with_stdio(false);
	cin.tie(0);
	long long n,q;
	cin>>n>>q;
	long long d[n+1],c[n+1],r[q],v[q];
	d[0]=0;
	c[0]=0;
	long long pr[n+1];
	pr[0]=0;
	for(long long i=1;i<=n;i++){
		cin>>d[i]>>c[i];
		pr[i]=pr[i-1]+c[i];
	}
	for(long long i=0;i<q;i++){
		cin>>r[i]>>v[i];
		long long l = r[i];
		long long r1 = n;
		while(l<r1){
			long long mid;
			if((l+r1)%2==0) mid = (l+r1)/2;
			else mid = (l+r1)/2+1;
			if(pr[mid]-pr[r[i]-1]==v[i]){
				cout<<mid<<endl;
				break;
			}
			if(pr[mid]-pr[r[i]-1]>v[i]){
			 r1 = mid;
			 if(pr[mid-1]-pr[r[i]-1]<=v[i]){
			 	cout<<mid<<endl;
			 	break;
			 }
			 }
			else{
			l = mid;
			if(pr[mid+1]-pr[r[i]-1]>v[i]){
				cout<<mid+1<<endl;
				break;
			}
			}
		}
		if(l==r1){
			cout<<0<<endl;
		}
	}
}
# Verdict Execution time Memory Grader output
1 Execution timed out 1567 ms 212 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Execution timed out 1531 ms 4940 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Execution timed out 1567 ms 212 KB Time limit exceeded
2 Halted 0 ms 0 KB -