Submission #982969

#TimeUsernameProblemLanguageResultExecution timeMemory
982969NeroZeinFish 3 (JOI24_fish3)C++17
9 / 100
2101 ms5904 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; bool ok = true; long long md = 0; 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 (!ok) { cout << -1 << '\n'; continue; } long long mn = LLONG_MAX; for (int i = r; i >= l; --i) { mn = min(mn, b[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...