# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
466989 | mtxas | Fountain (eJOI20_fountain) | C++14 | 3 ms | 332 KiB |
This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#include <bits/stdc++.h>
#define ll long long
#define vi vector<int>
#define vll vector<ll>
#define pb push_back
#define mfsadfp make_pair
#define pii pair<int, int>
#define pll pair<ll, ll>
#define fi first
#define se second
#define mii map<int, int>
#define all(a) a.begin(), a.end()
#define _fre() freopen("input.txt", "r", stdin)
#define turbo() cin.tie(0); cout.tie(0); ios_base::sync_with_stdio(false)
#define sz(x) ((int)x.size())
#define _for(a, b, c) for(int (a) = (b); (a) < (c); (a)++)
#define _foreq(a, b, c) for(int (a) = (b); (a) <= (c); (a)++)
#define _forneq(a, b, c) for(int (a) = (b); (a) >= (c); (a)--)
#define _forn(a, b, c) for(int (a) = (b); (a) > (c); (a)--)
using namespace std;
/***********************************************************************************
STRUCTS
************************************************************************************/
/***********************************************************************************
VARIABLES
************************************************************************************/
const int maxn = 2001;
int n, q;
int c[maxn], d[maxn], r[maxn], v[maxn];
/***********************************************************************************
FUNCTIONS
************************************************************************************/
int query(int R, int V){
int lastId = 0;
_foreq(j, R, n){
while(d[j] <= d[lastId]){
j++;
if(j == n+1) return 0;
} // d[j] > d[lastId]
V-= c[j];
if(V <= 0) return j;
lastId = j;
}
return 0;
}
/***********************************************************************************
MAIN
************************************************************************************/
int main(){
// _fre();
turbo();
cin>>n>>q;
_foreq(i, 1, n) cin>>d[i]>>c[i];
_for(i, 0, q) cin>>r[i]>>v[i];
_for(g, 0, q){
cout<<query(r[g], v[g])<<'\n';
}
}
Compilation message (stderr)
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |