Submission #467307

# Submission time Handle Problem Language Result Execution time Memory
467307 2021-08-22T13:19:39 Z shmad Fountain (eJOI20_fountain) C++14
30 / 100
1500 ms 3888 KB

#include <bits/stdc++.h>
 
#define nl '\n'
#define pb push_back
#define E exit(0)
#define all(v) v.begin(), v.end()
#define ff first
#define ss second
#define sz(s) (int)(s).size()
#define ll long long
#define int ll
#define oioi ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define vt vector
#define dbg(x) cerr << #x << " = " << x << nl

using namespace std;
using pii = pair<int, int>;
using vvi = vt< vt<int> >;
 
const int N = 1e6 + 5;
const int INF = 1e18 + 7;
const int MOD = 1e9 + 7;
const double eps = 1e-6;
const int B = 800;

void solve () {
    int n, q;
    cin >> n >> q;
    vt<int> diam(n + 1), cap(n + 1), r(q + 1), v(q + 1);
    for (int i = 1; i <= n; i++) cin >> diam[i] >> cap[i];
    for (int i = 1; i <= q; i++) {
        cin >> r[i] >> v[i];
        if (v[i] <= cap[r[i]]) {
            cout << r[i] << nl;
            continue;
        }
        bool fnd = 0;
        v[i] -= cap[r[i]];
        for (int j = r[i] + 1; j <= n; j++) {
            if (diam[j] > diam[r[i]]) {
                if (v[i] <= cap[j]) {
                    cout << j << nl;
                    fnd = 1;
                    break;
                }
                else v[i] -= cap[j], r[i] = j;
            }
        }
        if (!fnd) cout << "0\n";
    }
    cout << nl;
}

int test = 1;
 
signed main () {
//  freopen(".in", "r", stdin);
//  freopen(".out", "w", stdout);
    oioi
//  cin >> test; 
    while (test--) solve();
    return 0;
}
# Verdict Execution time Memory Grader output
1 Correct 0 ms 204 KB Output is correct
2 Correct 1 ms 204 KB Output is correct
3 Correct 1 ms 332 KB Output is correct
4 Correct 1 ms 332 KB Output is correct
5 Correct 3 ms 332 KB Output is correct
6 Correct 2 ms 332 KB Output is correct
7 Correct 1 ms 332 KB Output is correct
# Verdict Execution time Memory Grader output
1 Execution timed out 1576 ms 3888 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 0 ms 204 KB Output is correct
2 Correct 1 ms 204 KB Output is correct
3 Correct 1 ms 332 KB Output is correct
4 Correct 1 ms 332 KB Output is correct
5 Correct 3 ms 332 KB Output is correct
6 Correct 2 ms 332 KB Output is correct
7 Correct 1 ms 332 KB Output is correct
8 Execution timed out 1576 ms 3888 KB Time limit exceeded
9 Halted 0 ms 0 KB -