Submission #448052

# Submission time Handle Problem Language Result Execution time Memory
448052 2021-07-28T16:41:46 Z fuad27 Fountain (eJOI20_fountain) C++14
0 / 100
372 ms 4024 KB
#include<bits/stdc++.h>
using namespace std;
#define int long long
#define endl "\n"
#pragma GCC optimize("Ofast")
int32_t main () {
	int n, q;
	cin >> n >> q;
	vector<int> d(n, 0);
	vector<int> c(n, 0);
	vector<int> prefix(n+1, 0);
	bool increasing = true;
	for(int i=0;i<n;i++) {
		int a, b;
		cin >> a >> b;
		d[i] = a;
		c[i] = b;
		prefix[i+1] = prefix[i] + c[i];
		if(i > 0 and d[i] <= d[i-1])increasing = false;
	}
	while(q--) {
		int i, v;
		cin >> i >> v;
		i--;
		if(increasing) {
			int l = 0, u = n - 1, ans = 0;
			while(l < u) {
				int mid = l+(u-l)/2;
				if(prefix[mid+1] - prefix[i] >= v) {
					ans = mid;
					u = mid - 1;
				}
				else {
					l = mid + 1;
				}
			}
			if(prefix[n] > v) {
				cout<<0<<endl;
			}
			else
				cout<<ans+1<<endl;
		}
		else {
			int prev = i;
			while(v > 0 and i < n) {
				if(prev == i)v-=c[i];
				else if(d[i] > d[prev]) {
					v-=c[i];
					prev = i;
				}
				i++;
			}
			if(v > 0)cout<<0<<endl;
			else cout<<i<<endl;
		}
	}
}
# Verdict Execution time Memory Grader output
1 Correct 0 ms 204 KB Output is correct
2 Correct 2 ms 204 KB Output is correct
3 Correct 3 ms 204 KB Output is correct
4 Correct 4 ms 204 KB Output is correct
5 Incorrect 6 ms 204 KB Output isn't correct
6 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 372 ms 4024 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 0 ms 204 KB Output is correct
2 Correct 2 ms 204 KB Output is correct
3 Correct 3 ms 204 KB Output is correct
4 Correct 4 ms 204 KB Output is correct
5 Incorrect 6 ms 204 KB Output isn't correct
6 Halted 0 ms 0 KB -