Submission #1128239

#TimeUsernameProblemLanguageResultExecution timeMemory
1128239bvv23Fountain (eJOI20_fountain)C++20
60 / 100
1595 ms3312 KiB
/*
=======-==========---=-----------------------=-==================-==-=-=-===------------------------------------------------------
---------=--==-------------------------------=----========-----==--=-----=--------------------------------------------------------
--------=====-======-----------=-------------------=---=----=======-------==--------------------:---------------------------------
-------=----===--------------------=-------------==-----------=--------------=---------:-::-:::::::::::::::::::::::::---:::::-:::-
----------------------------------------------------------------------------------------------------------------------------------
--------------------------------------------------------------------:------:-------------------:::--------:-------------------:-:-
---------------:----------------------------------------:------------------------------------:::::::::::::::::----:::-::----------
--------:-::---:::-::::-----------::::::-:---:------:::::--------------:--------::--::::-:::::::::::::::::::::::::::::::-:::------
-------------------:::::::--------::-:::::::::---=+***++=++=----------:--::::::--:::::::-:::------:::--:::::---::::::::::---------
:::::::-::::--:::::::::::::::::::::::::::::--#%%@@@@@@@@@@@%+----------::------:::::::::::::::::-:-:-::::::::::::::-::-:---::-::--
::-:::::::---::::::::::----:--:-:-:::::---:=%@@@@@@@@@@@@@@@@*=--+------:::::::::::::::::::-::-:::--------:::::::::-::::::--------
::::::-:::::::::::::::::::::::::::::::::::-*%@@@@@@@@@@@@@@%*=*@@@@#+=-:::::::::::::::::::::::::::::::-::=*%%@@@@%#*=--::--::-----
::::::::::::::::::::::::::::::::::::::::::+#=%@@@@@@@@@@@@@@%@@@@@@@%#+=----:::::::::::::::::::::::::::=%@@@@@@@@@@@@%=::---------
::::::::::::::::::::::::::::--::::::::::::-@*+@@@@@@@@@@@@@@@@@@@%*+==========------::::::::::::::::::+@@@@@@@@@@@@@@@@+::-----:::
::::::::::::::::::::::::::::-------------::-+:=#%@%%%@@%@@@@@@@@*+=========+=========-::::::::::::::-*@@@@@%@%%%%%#%@@@@*-::::::::
:::::::::-:::::::::::::::::::::::::::::::::::-*#######%%@@@@@@@+=+++++++++***++*+**++*+:::::::::::==#@@@@@@@@@@@@@@%%#@@@+:::::::-
:::::::::::::::::::::::::::::::::::::::::::::-:--%%###%%@@@@@@%#**#****#%%%%%#%%####****-::::::::-+%@@@@@@@@@@@@@@@%@@@@@@=:------
:::::::::::::::.:::::::::::::::::::::::::::::::::++###%@@@@@%%%%%@%%###%%@@@@@@@@@@@%%###+::::::::%@@@@@@@@@@@@@@%**@@@@@@@=::::::
::::::::::::::..........::::::::::::::::::::::::::::-*%%@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@%%%#:..::=%@@@@@@@@@@@@@@@@@@@@@@@@@@=:::::
:::::::::::::::::::.::::::::::::::::::::::::::::::::::---%@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@%:.=#@@%#%@@@@@@@@@@@@@@@@@@@@@@@@*:::.
:::::::::::::::::::::::::::::::::::::::.....:::.........@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@#.:+%@@@@@@%#*+========++**###@@#*=...
:::::::::::::::::::::::::::::::::::::::::.:::.:.........%@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@#..:+*#%@@@@@@@@@@@@@@@@@@@@@@@#+:...
::::::::::::::::::...:...:::..::.:....:......:+-........+@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@#......:=**#%%%%%%%%@%%##*+=::::....
::::::::::::::::.............................-=:..::...-%@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@#...........:-=:..............::::.
.....::::::::.............................:-:........:.*@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@%:........+*#+..............::..:-
......:..::..:..........................::--:........::#@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@%-...:=++#%@=====:...............
:::.:::::::::::........................::::---::...::.:@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@+*:-+=++#%#+++*++***+=::.......:
::.:::::::::::..:...................::::::--=-:......*@@@@@@@@@@@@@@@@@@@@@@@@@%@@@@@@@@@@@@@@@@@@@**-=+++#%*++**+=--=+++**+-:...=
::::::::.....:......::...........:::::::-::---::::::=@@@@@@@@@@@@@@@@@@@@@@@@@@%@@@@@@@@@@@@@@@@@@@@*#+=++*#+++****+==+===+++**=-.
:.:..:::::.:::.................:::::::-:::----:-:::-%@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@%*##++**++****###%%#*++***+===
:::::::::::::.::...............:--::--::::====-::=+@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@%%@*#****+***##*#%%#***=+===
:::::::::::::.::.:..:..........:::::---:::--=---==%@@@@@@@@@@@@@@@@@%%@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@%%%##%##**++*#******++++++
..........................:::::..::::--:---==--:%@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@%#***#%######**+
.......::...............:::.:.....:::----====-:.@@@@@@@@@@@@@%%@@@%#%@@%@@@@%%%@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@%######*+:::---:
......::::::::::::::.::.::.:....::::....--+-*=::@@@@@@@@@@-....+%%%##%@@@%%%%%@@@@%%@@@@@@@@@@@@@@@@@@@@@@@@@@@=-==---=-:.........
...:::::::.:::::::.:::.:........::......::::-:..-=+*#%@@@@#+-::-%@@@%%%%%#%@@@@@@@**%@@@@@@@@@@@@@@@@@@@@@@@@@#:-:..............::
::::::::::::::::.:-=-::........:::............:::=....-=+*##%%%%@@@@@@@@@@@@@@@@@%+*+@@@@@@@@@@@@@@@@@@@@@@@@@:..-:.......:-:----:
:::::::::::::::.:-==:.........::..::-::....-=++*++*+++=+++*#@@@@@@@@@@@@@@@%%@@@@@#@#@@@@@@@@@@@@@@@@@@@@@@%%+.............:-=-:..
.::::::::::::..---=-:::.::.::----=**++=..:==***@%%%%%###*#%%%%%%@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@*=::....................
..::::::::::::=====-:::::::--*++=*#**#*..=+**#%@@@%%@%%%#%%%%%@@@@@%@@@@@%%@@@@@@@@@%@@%%%@@@@@@@@@@@@@@@@*..........:::.::.......
:::::::::.::-=+====-:::..::=*####**#%%#..=#**%%%@@@@%%%%%%%%@%%%%%@@@@@%@%%@%%%%%%@%%%%%%%%@@@@@@@@@@@@@@@%-:...........--*#*++---
:::::::::::::-===--:::::::--=*%%%%@@@%#.:=+#%%%@@@@%***##%%@@@@@@@@%%@%@@@@@@%%%#%%%###%%%@@@@@@@@@@@@@@@@@%%#*#=-:..........:...-
::::::::::::::::==--::::-===*##%@@@@@%+.=######%%#+#*++++#%++#%%%%@%%@@@@@@@@@@@@@@@%@@@%@@@@@@@@@@@@@@@@@@%%@@@@@*=++==***=-:::-#
.:.::..:::::::::..::::::-+**#%@@@@@@@@=:+###%#%#*==#*****#%+.:*####*=#%%%%%@%%@%%#####**%%%@@@@@@@@@@@@@@@@*@@@@%#%*+*%@@@@@@%#**%
::::::::::::::.....:---==+###%@@@@@@@@=-##%%%###*==##%#####+.:+###*+=%%%%#%**%%#*****+*#%%@@@@@@@@@@@@@@@@@@%@@%%@##%#%%%%%@@@%##*
::::::...::---+:.....=+=*%#%@@@@%%@@@@=+##%%####*=#%@%%%#%%#..=*#*+-#@@@%#++*##*+*=::-*%@@@@@%%#@@@@@@@@@@@@@%#%@@@%%%%@@@%@@@@%#*
:--=-..:=----=-.......=##@@@@@@@@@@@@@**###%####**@@@@@@@@%%..-*#+:#@@@@*=+=:+-:..::=#%%@@%##**@%@@@@@@@@@@@@@@@@@%@@@@@@@@@@@@@@#
........-++*%=....::::..=%@@@@@@@@@@@@**#######*#@@@@@@@@@@#..:+*-+@@@@%+::.:...--:+%%@@@@@%@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
----+*++**##%+=-..:.:+#*##@@@@@@@@@@@@+#######*#@@@@@@@@@@@+..-++:@@@@#-...::.-=::=%%%@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@%%@
###%*++#@@%@%***%@@%###@@@@%%@@@@@@@@@+########@@@@@@%@@@@@:..-*=+@@@#-:.....:-+**#*#%@@@@@@@@@@@@@@@@@@@@@@@%@@@@@@@@@@@@@@@@@@%%
#===+#%@@@@@@%%@@@@%@@%*-.+:..:+@@@@@%*######*-.:=::..==---..:-*+:.:---...-:=*+=+*###%@@@@@@@@@@@@@@@@@@@@@@@%@@@@@@@@@@@@@@@@@@@@
.:-::..:-==:...-==-=...........:--::.:######*:..............:=*##*::-=-..-:.=++=*%%%%@@@@@@@@@@@@@@@@@@@@@@@@%%@@@@@@@@@@@@@@@@@@@
.:::--:::-=-.........................=*#####+..........:...-*%@@@+-+@-..:...:=#%@@@@@@@@@@@@@@@@@@@@@@@@@@@@@#++=--::-=+@@@@@@@@@@
:::==+****+-:.......................:*######+........+#%*%@@@@@@#-:-#=-#=:.:*%@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@+=++=++=*##%+@@@@@@@@@
.....:=++**=:..:.:..................-*#%######:.......::+%@@@%#++=-=+%#=..**%%%%@%%@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@%@@@@%+@@@@@@@@
.........-:...:-...................:+#%##%%%@@%:.........--::::##==.....:-=*##%%##%@@@@@@@@@@@@@@@@@@@@@@@@@@@%%%@%@@@@@@++@@@@@@@
::................................-+*#%%%@@@@@@+......:..:::-:-==.....:+=++*######@@@@@@@@@@@@@@@@@@@@@@@@@@@%%@@@@@@@@@@@*#@@@@@@
...........................:-=+=..=*%@@@@@@@@%=...:........---+*=:..:=+-*#@@@%%%@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@#@@@@@@
........................-##=*%@@@@@@@@@%+-:+@@#-..:--::::...:=+::==**#*#%%@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
:......................:++===##%%%%%*=:..-#**%#**--**-::..=*##==*%%%%%@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
=-..................................::---==+=:::-+#%@%%##%%#@@@#%%@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
+*-...............................................-#@@@@@%@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@#=-=*@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
............................................:+#*==+--=----=*##@@@@@@@@@@@@@@@@@@@@@@@@@@@@@%++=....:+@@@@@@@@@@@@@@@@@@@%%%*+-.:--
*/
// Ahmadov orz
/// successful failure
/// MALLL, SKILL ISSUEZ
#include <bits/stdc++.h>
/// #include <ext/pb_ds/assoc_container.hpp>
using namespace std;
/// using namespace __gnu_pbds;
#define int long long
#define pb push_back
#define pii pair<int, int>
#define all(v) v.begin(),v.end()
#define ff first
#define ss second
#define drop(x) cout<<x<<endl;return
// template <class T>
// using isTree = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;

/// sometimes you gotta think simple
struct custom_hash {
    size_t operator()(uint64_t x) const {
        static const uint64_t FIXED_RANDOM = chrono::steady_clock::now().time_since_epoch().count();
        x ^= FIXED_RANDOM;
        return x ^ (x >> 16);
    }
};
int binpow(int a,int b,int mod){ 
    if(b==0) return 1; 
    int half = binpow(a,b>>1,mod);
    int res = (half*half)%mod;
    if(b&1) res=(res*a)%mod;
    return res;
}
void failure()
{
    int n,Q;
    cin >> n >> Q;
    vector <int> drr(n+1), crr(n+1), pref(n+1,0);
    int subtask2 = 1; 
    for (int i = 1; i <= n; i++) {
        cin >> drr[i] >> crr[i];
        pref[i] = pref[i-1] + crr[i];
    }
    for (int i = 1; i <= n-1; i++) {
        subtask2 &= (drr[i] < drr[i+1]);    
    }
    while (Q--) {
        int d,v;
        cin >> d >> v;
        if (subtask2) {
            int l = d, r = n+1;
            int ans = 0;
            // y den baslasam, x e qeder tokulse, pref[x]-pref[y-1] qeder su lazim olur, bundan cox su olsa demeli daha cox gede biler
            while (l <= r) {
                int mid = (l+r)>>1;
                if ((pref[mid] - pref[d-1]) >= v) {
                    ans = mid;
                    r = mid-1;
                }
                else {
                    l = mid+1;
                }
            }
            cout << ans << endl;
        }
        else {
            int prev = -100;
            bool check = 0;
            for (int i = d; i <= n; i++) {
                if (drr[i] > prev) {
                    v -= crr[i];
                    if (v <= 0) {
                        cout << i << endl;
                        check = 1;
                        break;
                    }
                    prev = drr[i];
                }
                if (check) {
                    cout << 0 << endl;
                }
            }
        }
        
    }
}   
signed main() {  
    ios_base::sync_with_stdio(0); 
    cin.tie(NULL);                
    cout.tie(NULL);
    int tt = 1;
    // cin >> tt;
    while (tt--)
    {
        failure();
    }
}
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...