제출 #467307

#제출 시각아이디문제언어결과실행 시간메모리
467307shmadFountain (eJOI20_fountain)C++14
30 / 100
1576 ms3888 KiB


#include <bits/stdc++.h>
 
#define nl '\n'
#define pb push_back
#define E exit(0)
#define all(v) v.begin(), v.end()
#define ff first
#define ss second
#define sz(s) (int)(s).size()
#define ll long long
#define int ll
#define oioi ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define vt vector
#define dbg(x) cerr << #x << " = " << x << nl

using namespace std;
using pii = pair<int, int>;
using vvi = vt< vt<int> >;
 
const int N = 1e6 + 5;
const int INF = 1e18 + 7;
const int MOD = 1e9 + 7;
const double eps = 1e-6;
const int B = 800;

void solve () {
    int n, q;
    cin >> n >> q;
    vt<int> diam(n + 1), cap(n + 1), r(q + 1), v(q + 1);
    for (int i = 1; i <= n; i++) cin >> diam[i] >> cap[i];
    for (int i = 1; i <= q; i++) {
        cin >> r[i] >> v[i];
        if (v[i] <= cap[r[i]]) {
            cout << r[i] << nl;
            continue;
        }
        bool fnd = 0;
        v[i] -= cap[r[i]];
        for (int j = r[i] + 1; j <= n; j++) {
            if (diam[j] > diam[r[i]]) {
                if (v[i] <= cap[j]) {
                    cout << j << nl;
                    fnd = 1;
                    break;
                }
                else v[i] -= cap[j], r[i] = j;
            }
        }
        if (!fnd) cout << "0\n";
    }
    cout << nl;
}

int test = 1;
 
signed main () {
//  freopen(".in", "r", stdin);
//  freopen(".out", "w", stdout);
    oioi
//  cin >> test; 
    while (test--) solve();
    return 0;
}
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...