제출 #990830

#제출 시각아이디문제언어결과실행 시간메모리
990830grtFish 3 (JOI24_fish3)C++17
0 / 100
2070 ms5160 KiB
#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 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...