제출 #990831

#제출 시각아이디문제언어결과실행 시간메모리
990831grtFish 3 (JOI24_fish3)C++17
9 / 100
2088 ms5132 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; ll 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 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...