Submission #827422

# Submission time Handle Problem Language Result Execution time Memory
827422 2023-08-16T12:59:39 Z Rayyan1108 Fountain (eJOI20_fountain) C++17
0 / 100
524 ms 524288 KB
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define pll pair<ll, ll>
void print(ll Z) {
    cout << Z << endl;
}
struct threeVar {
     ll first, second, third;
};
ll ps[100090];
ll binser(ll L, ll R, ll X, ll Y) {
    while (L < R) {
        ll mid = (L+R)/2;
        if(ps[mid] - Y == X) {
            return mid;
        }
        else if(ps[mid] - Y > X) {
            return binser(L, mid, X, Y);
        }
        else {
            return binser(mid+1, R, X, Y);
        }
    }
    return L;
    
}
int main() {
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
    ll N, Q;
    cin >> N >> Q;
    pll arr[N+4];
    vector<threeVar> V[N+2];
    bool isST2 = 1;
    ps[0] = 0;
    for(int i=1; i<=N; i++) {
        cin >> arr[i].first >> arr[i].second;
        if(arr[i].first <= arr[i].second) {
            isST2 = 0;
        }
        ps[i] = ps[i-1] + arr[i].second;
    }
    if(!isST2) {
    for(int i=1; i<=N; i++) {
        V[i].push_back({arr[i].first, arr[i].second, i});
        for(int j=1; j<i; j++) {
            if(arr[i].first > V[j].back().first) {
                if(!V[j].empty()) {
                    V[j].push_back({arr[i].first, V[j].back().second + arr[i].second, i});
                }
            }
        }
    }
    while(Q--) {
        ll X, Y;
        cin >> X >> Y;
        if(!V[X].empty()) {
        ll Z = V[X].back().second;
        if(Y > Z) {
            print(0);
        }
        else {
            ll ans = V[X][0].third;
            bool firstTime = 1;
            for(auto i: V[X]) {
                if(i.second < Y) {
                    ans = i.third;
                }
                else if(i.second == Y) {
                    ans = i.third;
                    break;
                }
                else {
                    if(firstTime) {
                        firstTime = 0;
                        ans = i.third;
                    }
                else {break;}
                }
            }
            print(ans);
        }
        }
    }
    }
    else {
        while (Q--) {
            ll X, Y;
            cin >> X >> Y;
            if(Y > ps[N] - ps[X-1]) {
                print(0);
                continue;
            }
            ll ans = binser(1, N, Y, ps[X-1]);
            print(ans);
        }
        
    }
    return 0;
}
# Verdict Execution time Memory Grader output
1 Incorrect 1 ms 212 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 197 ms 5672 KB Output is correct
2 Runtime error 524 ms 524288 KB Execution killed with signal 9
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 1 ms 212 KB Output isn't correct
2 Halted 0 ms 0 KB -