Submission #769900

# Submission time Handle Problem Language Result Execution time Memory
769900 2023-06-30T12:46:06 Z BlockOG Fountain (eJOI20_fountain) C++14
0 / 100
162 ms 2764 KB
#include <iostream>
#include <vector>
#include <utility>
#include <algorithm>
#include <cstring>
#include <set>
#include <cmath>

using namespace std;

int main() {
    ios::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);

    int n, q; cin >> n >> q;
    int diameters[n];
    int next[n];
    int capacities[n];
    for (int i = 0; i < n; i++) cin >> diameters[i] >> capacities[i];
    
    bool all_increasing = true;
    for (int i = 0; i < n; i++) {
        next[i] = n;
        for (int j = i + 1; j < n; j++) {
            if (diameters[j] > diameters[i]) {
                next[i] = j;
                if (j - i > 1) all_increasing = false;
                break;
            }
        }
    }
    
    if (all_increasing) {
        for (int i = 1; i < n; i++) diameters[i] += diameters[i - 1];
        
        for (int iq = 0; iq < q; iq++) {
            int r, v; cin >> r >> v; r--;
            if (r > 0) v += diameters[r - 1];
            if (v > diameters[n - 1]) {
                cout << 0 << endl;
                continue;
            }
            
            int l = 0, ri = n - 1;
            while (l < ri) {
                int mid = (l + ri) / 2;
                if (diameters[mid] >= v) ri = mid;
                else l = mid + 1;
            }
            
            cout << l + 1 << endl;
        }
    } else {
        for (int iq = 0; iq < q; iq++) {
            int r, v; cin >> r >> v; r--;
            for (; r < n; r = next[r]) {
                v -= capacities[r];
                if (v <= 0) break;
            }
            
            if (r == n) cout << 0 << endl;
            else cout << r + 1 << 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 324 KB Output is correct
4 Correct 2 ms 212 KB Output is correct
5 Incorrect 4 ms 212 KB Output isn't correct
6 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 162 ms 2764 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 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 324 KB Output is correct
4 Correct 2 ms 212 KB Output is correct
5 Incorrect 4 ms 212 KB Output isn't correct
6 Halted 0 ms 0 KB -