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>
using namespace std;
#define fast ios::sync_with_stdio(false);cin.tie(NULL)
#define fi first
#define se second
#define all(v) (v).begin(),(v).end()
#define pb push_back
#define eb emplace_back
#define pre(a) cout<<fixed; cout.precision(a)
typedef long long ll;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
const long long INF = 1e18;
const int inf = 1e9;
ll n, h, l, r, ans;
priority_queue<ll, vector<ll>, less<ll>> L;
priority_queue<ll, vector<ll>, greater<ll>> R;
ll arr[200010];
bool Swap() {
ll x = L.top() + l;
ll y = R.top() + r;
if(x <= y) return false;
ans += x - y;
L.pop();
R.pop();
L.push(y - l);
R.push(x - r);
return true;
}
int main() {
fast;
cin >> n >> h;
for(int i=0; i<n; i++) {
l -= h;
r += h;
cin >> arr[i];
L.push(arr[i] - l);
R.push(arr[i] - r);
while(Swap());
}
cout << ans;
}
# | 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... |
# | 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... |