# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
1110171 | vjudge1 | Fish 3 (JOI24_fish3) | C++17 | 2068 ms | 4976 KiB |
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 fi(i, a, b) for( int i = a; i <= b; i++ )
#define fid(i, a, b) for( int i = a; i >= b; i-- )
#define getbit(x, i) ((x>>i)&1)
#define ll long long
#define pb push_back
#define pii pair<int,int>
#define pli pair<ll,int>
#define pll pair<ll,ll>
#define st first
#define nd second
#define mp make_pair
#define HTManh ""
#define maxn 100009
#define endl '\n'
using namespace std;
int n;
ll d;
ll c[300009];
int q;
int main()
{
ios_base::sync_with_stdio(0);
cin.tie(NULL); cout.tie(NULL);
if (fopen(HTManh".inp", "r"))
{
freopen(HTManh".inp", "r", stdin);
freopen(HTManh".out", "w", stdout);
}
cin >> n >> d;
fi(i,1,n) cin >> c[i];
cin >> q;
while(q--)
{
int l, r;
cin >> l >> r;
bool flag = 1;
ll res = 0;
ll gh = 1e18;
fid(i,r,l)
{
if (gh >= c[i])
{
gh = c[i];
}
else
{
if (c[i]%d > gh)
{
flag = 0;
break;
}
ll them = (c[i]-gh-1)/d + 1;
res += them;
gh = c[i] - them*d;
//cout << res << " " << gh << endl;
}
}
if (flag) cout << res << endl;
else cout << -1 << endl;
}
}
Compilation message (stderr)
# | 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... |