Submission #596877

# Submission time Handle Problem Language Result Execution time Memory
596877 2022-07-15T08:37:46 Z Cookie Fountain (eJOI20_fountain) C++14
0 / 100
49 ms 8056 KB
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define vt vector
#define pb push_back
const int mxn = 2e5 + 3;
int n, q;
ll a[100001], b[100001];
int main(){
	ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
	cin >> n >> q;
	for(int i = 1; i <= n; i++)cin >> a[i] >> b[i];
	if(n <= 1000){
	    for(int i = 0; i < q; i++){
	        ll r, v; cin >> r >> v;
	        if(v <= b[r]){
	            cout << r << "\n";
	        }else{
	            ll curr = a[i];
	            v -= b[r];
	            for(int j = r + 1; j <= n; j++){
	                if(a[j] > curr){
	                    v -= b[j];
	                    if(v <= 0){
	                        cout << j << "\n";
	                        break;
	                    }
	                    curr = a[j];
	                }
	            }
	            if(v > 0)cout << 0 << "\n";
	        }
	    }
	}else{
	    ll p[n + 1] = {};
	    for(int  i = 1; i <= n; i++)p[i] = p[i - 1] + b[i];
	    for(int i = 0; i < q; i++){
	       ll rr, v; cin >> rr >> v;
	       int l = rr, r = n, ans = 0;
	       while(l <= r){
	           int mid = (l + r) >> 1;
	           if(p[l] - p[i - 1] >= v){
	               ans = l; r = mid - 1;
	           }else{
	               l = mid + 1;
	           }
	       }
	       cout << ans << "\n";
	    }
	}
}
# Verdict Execution time Memory Grader output
1 Incorrect 0 ms 212 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Runtime error 49 ms 8056 KB Execution killed with signal 11
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 0 ms 212 KB Output isn't correct
2 Halted 0 ms 0 KB -