답안 #632217

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
632217 2022-08-19T16:27:16 Z Jovan26 Fountain (eJOI20_fountain) C++14
30 / 100
287 ms 2064 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-1]+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 = 0 ;
			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;	
		}
}
}
}
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 2 ms 212 KB Output is correct
3 Correct 2 ms 212 KB Output is correct
4 Correct 3 ms 212 KB Output is correct
5 Correct 5 ms 212 KB Output is correct
6 Correct 5 ms 212 KB Output is correct
7 Correct 4 ms 212 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Incorrect 287 ms 2064 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 2 ms 212 KB Output is correct
3 Correct 2 ms 212 KB Output is correct
4 Correct 3 ms 212 KB Output is correct
5 Correct 5 ms 212 KB Output is correct
6 Correct 5 ms 212 KB Output is correct
7 Correct 4 ms 212 KB Output is correct
8 Incorrect 287 ms 2064 KB Output isn't correct
9 Halted 0 ms 0 KB -