This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#include <bits/stdc++.h>
#define int long long
using namespace std;
#define all(v) (v).begin(), (v).end()
#define rall(v) (v).rbegin(), (v).rend()
#define rep(i, a, b) for(int i = (a); i < (b); i++)
#define sz(v) ((int)((v).size()))
template<typename T>
void chmax(T &x, const T &v) { if (x < v) x = v; }
template<typename T>
void chmin(T &x, const T &v) { if (x > v) x = v; }
using pii = pair<int, int>;
using vi = vector<int>;
using ll = long long;
string to_string(string s) { return s; }
template <typename T> string to_string(T v) {
bool first = true;
string res = "[";
for (const auto &x : v) {
if (!first)
res += ", ";
first = false;
res += to_string(x);
}
res += "]";
return res;
}
template <typename A, typename B>
string to_string(pair<A, B> p) {
return "(" + to_string(p.first) + ", " + to_string(p.second) + ")";
}
void dbg_out() { cout << endl; }
template <typename Head, typename... Tail> void dbg_out(Head H, Tail... T) {
cout << ' ' << to_string(H);
dbg_out(T...);
}
#ifdef DEBUG
#define dbg(...) cout << "(" << #__VA_ARGS__ << "):", dbg_out(__VA_ARGS__)
#else
#define dbg(...)
#endif
signed main() {
ios_base::sync_with_stdio(false);
cin.tie(0);
int nbFish, delta;
cin >> nbFish >> delta;
vector<int> ideal(nbFish);
rep(i, 0, nbFish) {
cin >> ideal[i];
}
int nbReq; cin >> nbReq;
rep(iReq, 0, nbReq) {
int lft, rgt;
cin >> lft >> rgt;
--lft, --rgt;
int curVal = ideal[rgt];
int answer = 0;
for (int iFish = rgt-1; iFish >= lft; --iFish) {
chmin(curVal, ideal[iFish]);
// ideal - giveA*D <= curVal
// ideal - curVal <= giveA*D
int giveA = (ideal[iFish] - curVal + delta - 1) / delta;
curVal = ideal[iFish] - giveA*delta;
if (curVal < 0) {
answer = -1;
break;
}
answer += giveA;
}
cout << answer << '\n';
}
}
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |