Submission #990830

# Submission time Handle Problem Language Result Execution time Memory
990830 2024-05-31T13:02:56 Z grt Fish 3 (JOI24_fish3) C++17
0 / 100
2000 ms 5160 KB
#include <bits/stdc++.h>
#define ST first
#define ND second
#define PB push_back

using namespace std;
using ll = long long;
using pi = pair<int, int>;
using vi = vector<int>;

const int nax = 300 * 1000 + 10;

int main() {
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    int n, q, d;
    cin >> n >> d;
    vector<ll> a(n);
    for (ll &x : a) cin >> x;
    cin >> q;

    while (q--) {
        int l, r;
        cin >> l >> r;
        l--, r--;
        ll ans = 0;
        vector<ll> memo = a;
        bool ok = true;
        for (int i = r - 1; i >= l; --i) {
            ll diff = a[i + 1] - a[i];
            if (diff < 0) {
                ll me = (-diff - 1) / d + 1;
                ans += me;
                a[i] -= d * me;
                if (a[i] < 0) ok = false;
            }
        }
        a = memo;
        if (!ok) cout << "-1\n";
        else cout << ans << "\n";
    }
}
# Verdict Execution time Memory Grader output
1 Correct 1 ms 348 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 23 ms 512 KB Output is correct
5 Incorrect 1 ms 344 KB Output isn't correct
6 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Execution timed out 2066 ms 5160 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1543 ms 4948 KB Output is correct
2 Execution timed out 2070 ms 5160 KB Time limit exceeded
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Execution timed out 2021 ms 4288 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 348 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 23 ms 512 KB Output is correct
5 Incorrect 1 ms 344 KB Output isn't correct
6 Halted 0 ms 0 KB -