Submission #463576

#TimeUsernameProblemLanguageResultExecution timeMemory
463576Em1LFountain (eJOI20_fountain)C++14
30 / 100
1590 ms1488 KiB
#include <bits/stdc++.h>
using namespace std;

#define fountain    pair<int,int>
#define len         first
#define vol         second

void fastIO()
{
    ios_base::sync_with_stdio(false);
    
    cin.tie(NULL);
    cout.tie(NULL);
}

int main()
{
    fastIO();
    
    int n, q, pos, lits;
    
    cin >> n >> q;
    
    vector <fountain> v(n);
    
    vector <int> next(n, -1);
    
    for (int i = 0; i < n; i++) cin >> v[i].len >> v[i].vol;
    
    for (int i = 0; i < n; i++)
        for (int j = i + 1; j < n; j++)
            if (v[j].len > v[i].len)
            {
                next[i] = j;
                
                break;
            }
            
    for (int i = 0; i < q; i++)
    {
        cin >> pos >> lits; pos--;
        
        while (pos != -1)
        {
            lits -= v[pos].vol;
            
            if (lits <= 0)
            {
                cout << pos + 1 << '\n';
                
                break;
            }
            
            pos = next[pos];
        }
        
        if (lits > 0) cout << 0 << '\n';
    }
}
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...