Submission #448056

# Submission time Handle Problem Language Result Execution time Memory
448056 2021-07-28T16:48:21 Z fuad27 Fountain (eJOI20_fountain) C++14
60 / 100
1500 ms 6288 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 = i, 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 316 KB Output is correct
5 Correct 6 ms 204 KB Output is correct
6 Correct 7 ms 204 KB Output is correct
7 Correct 5 ms 204 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 391 ms 3168 KB Output is correct
2 Correct 455 ms 6288 KB Output is correct
# 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 316 KB Output is correct
5 Correct 6 ms 204 KB Output is correct
6 Correct 7 ms 204 KB Output is correct
7 Correct 5 ms 204 KB Output is correct
8 Correct 391 ms 3168 KB Output is correct
9 Correct 455 ms 6288 KB Output is correct
10 Correct 8 ms 332 KB Output is correct
11 Execution timed out 1579 ms 2908 KB Time limit exceeded
12 Halted 0 ms 0 KB -