Submission #990828

# Submission time Handle Problem Language Result Execution time Memory
990828 2024-05-31T12:54:28 Z grt Fish 3 (JOI24_fish3) C++17
0 / 100
2000 ms 12428 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;
        ll open = 0;
        for (int i = r; i >= l; --i) {
            ll dif = (i == l ? a[i] : a[i] - a[i - 1]);
            ll demand = 0;
            if (dif < 0) {
                demand = (abs(dif) - 1) / d + 1;
            } else {
                demand = - (dif / d);
            }
            if (demand > 0) {
                ans += (ll)i * demand;
                open += demand;
            } else {
                ll me = min(-demand, open);
                ans -= me * i;
                open -= me;
            }
        }
        if (open > 0) cout << "-1\n";
        else cout << ans << "\n";

    }
}
# Verdict Execution time Memory Grader output
1 Correct 0 ms 344 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 8 ms 464 KB Output is correct
5 Incorrect 306 ms 12428 KB Output isn't correct
6 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Execution timed out 2062 ms 3668 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 547 ms 7252 KB Output is correct
2 Execution timed out 2058 ms 6348 KB Time limit exceeded
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Execution timed out 2037 ms 3408 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 0 ms 344 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 8 ms 464 KB Output is correct
5 Incorrect 306 ms 12428 KB Output isn't correct
6 Halted 0 ms 0 KB -