이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include<bits/stdc++.h>
using namespace std;
class SlopeTrick{
private:
priority_queue<long long> lft;
priority_queue<long long, vector<long long>, greater<long long>> rgt;
long long offset = 0;
public:
long long min_value = 0;
void insert(int x){
if(lft.empty()){lft.push(x), rgt.push(x); return;}
long long l_value = lft.top() - offset;
long long r_value = rgt.top() + offset;
if(x < l_value){
lft.pop();
lft.push(x + offset);
lft.push(x + offset);
rgt.push(l_value - offset);
min_value += l_value - x;
}
else if(x > r_value){
rgt.pop();
rgt.push(x - offset);
rgt.push(x - offset);
lft.push(r_value + offset);
min_value += x - r_value;
}
else{
lft.push(x + offset);
rgt.push(x - offset);
}
}
void shift(int h){
offset += h;
}
};
int main(){
ios_base::sync_with_stdio(false);
cin.tie(0); cout.tie(0);
int N, h;
cin>> N>> h;
vector<int> a(N);
for(int i=0; i<N; i++){
cin>> a[i];
}
SlopeTrick st;
for(int i=0; i<N; i++){
st.insert(a[i]);
st.shift(h);
}
cout<< st.min_value;
return 0;
}
# | 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... |