Submission #982963

#TimeUsernameProblemLanguageResultExecution timeMemory
982963NeroZeinFish 3 (JOI24_fish3)C++17
0 / 100
2066 ms5896 KiB
#include "bits/stdc++.h" using namespace std; #ifdef Nero #include "Deb.h" #else #define debug(...) #endif int main() { ios::sync_with_stdio(false); cin.tie(nullptr); int n; long long d; cin >> n >> d; vector<long long> c(n); for (int i = 0; i < n; ++i) { cin >> c[i]; } int q; cin >> q; while (q--) { int l, r; cin >> l >> r; --l, --r; int ind = 0; bool ok = true; long long md = 0, mn = LLONG_MAX; vector<long long> b = c; for (int i = l; i <= r; ++i) { b[i] -= md; if (b[i] < 0) { ok = false; break; } long long tmp = b[i] % d; b[i] -= tmp; md += tmp; if (b[i] <= mn) { ind = i; mn = b[i]; } } if (!ok) { cout << -1 << '\n'; continue; } for (int i = ind; i <= r; ++i) { b[i] = 0; } for (int i = l; i < ind; ++i) { b[i] -= mn; } long long ans = 0; for (int i = l; i <= r; ++i) { ans += b[i] / d; } cout << ans << '\n'; } return 0; }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...