Submission #576490

# Submission time Handle Problem Language Result Execution time Memory
576490 2022-06-13T06:41:04 Z vqpahmad Fountain (eJOI20_fountain) C++14
60 / 100
72 ms 2468 KB
#include <bits/stdc++.h>
#define ll long long
#define endl '\n'
#define all(a) a.begin(),a.end()
#define mod (ll)(10000007)
using namespace std;
const int mx = 1e6 + 15;

int main()
{
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
    int n,q;
    cin >> n >> q;
    vector<pair<int,int>> a(n);//fist diamter , second is water
    for (int i=0;i<n;i++){
        cin >> a[i].first >> a[i].second;
    }
    if (n<=1000&&q<=2000){
        while (q--){
            int d,v;
            cin >> d >> v;
            d--;
            int mx=a[d].first;
            v-=a[d].second;
            d++;
            while(d<n&&v>0){
                if (a[d].first > mx){
                    mx = a[d].first;
                    v-=a[d].second;
                }
                d++;
            }
            d<n?cout << d << endl:cout << 0 << endl;

        }
    }
    else {
        vector<ll> pref(n+1);
        for (int i=1;i<=n;i++){
            pref[i] = pref[i-1]+a[i-1].second;
        }
        while (q--){
            int d,v;
            cin >> d >> v;
            ll num = pref[d-1];
            int up = lower_bound(all(pref),num+v)-pref.begin();
            up <= n ? cout << up <<endl : cout << 0 << endl;
        }
    }
}
# Verdict Execution time Memory Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 1 ms 212 KB Output is correct
3 Correct 1 ms 212 KB Output is correct
4 Correct 1 ms 340 KB Output is correct
5 Correct 2 ms 212 KB Output is correct
6 Correct 2 ms 340 KB Output is correct
7 Correct 2 ms 212 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 63 ms 2468 KB Output is correct
2 Correct 72 ms 2436 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 1 ms 212 KB Output is correct
3 Correct 1 ms 212 KB Output is correct
4 Correct 1 ms 340 KB Output is correct
5 Correct 2 ms 212 KB Output is correct
6 Correct 2 ms 340 KB Output is correct
7 Correct 2 ms 212 KB Output is correct
8 Correct 63 ms 2468 KB Output is correct
9 Correct 72 ms 2436 KB Output is correct
10 Incorrect 1 ms 340 KB Output isn't correct
11 Halted 0 ms 0 KB -