제출 #440714

#제출 시각아이디문제언어결과실행 시간메모리
440714haxormanFountain (eJOI20_fountain)C++14
30 / 100
87 ms2128 KiB
#include <bits/stdc++.h>
using namespace std;

const int mxN = 1e5 + 7;

int d[mxN], c[mxN];

int32_t main() {
    ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);

    int n, q;
    cin >> n >> q;

    for (int i = 0; i < n; ++i) {
        cin >> d[i] >> c[i];
    }

    vector<int> pref(n);
    pref[0] = c[0];
    for (int i = 1; i < n; ++i) {
        pref[i] = pref[i - 1] + c[i];
    }

    int tot = q;
    while (q--) {
        int r, v;
        cin >> r >> v;
        --r;

        if (n <= 1000 && tot <= 1000) {
            int prev = 0;
            while (v > 0 && r < n) {
                if (d[r] > prev) {
                    v -= c[r];
                    prev = d[r];
                }

                if (v > 0) {
                    ++r;
                }
            }

            if (r == n) {
                cout << "0\n";
            }
            else {
                cout << r + 1 << "\n";
            }
            continue;
        }

        v += (r ? pref[r - 1] : 0);
        auto it = lower_bound(pref.begin(), pref.end(), v);
        if (it == pref.end()) {
            cout << "0\n";
        }
        else {
            cout << it - pref.begin() + 1 << "\n";
        }
    }
}
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...