제출 #1203442

#제출 시각아이디문제언어결과실행 시간메모리
1203442LucaIlieFish 3 (JOI24_fish3)C++20
9 / 100
2096 ms5160 KiB
#include <bits/stdc++.h> using namespace std; const int MAX_N = 3e5; const int MAX_LOG_N = 18; const long long INF = 1e18; int n; long long d; int nxt[MAX_LOG_N + 1][MAX_N + 1]; long long a[MAX_N + 1], sum[MAX_N + 1], surplus[MAX_N + 1], sumsurplus[MAX_N + 1]; long long cost[MAX_LOG_N + 1][MAX_N + 1]; int main() { ios_base::sync_with_stdio(false); cin.tie(nullptr); cin >> n >> d; for (int i = 1; i <= n; i++) cin >> a[i]; int q; cin >> q; for (; q > 0; q--) { int l, r; cin >> l >> r; long long ans = 0; long long h = a[r]; for (int i = r - 1; i >= l; i--) { long long k = (a[i] - h + d - 1) / d; k = max(k, 0LL); h = a[i] - k * d; ans += k; } cout << (h < 0 ? -1 : 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...