| # | 제출 시각 | 아이디 | 문제 | 언어 | 결과 | 실행 시간 | 메모리 |
|---|---|---|---|---|---|---|---|
| 1363191 | m5588ohammed | Safety (NOI18_safety) | C++20 | 43 ms | 8604 KiB |
#include <bits/stdc++.h>
using namespace std;
#define endl '\n'
#define mod 1000000007
#define int long long
int n,arr[500001];
int Linf=-1e9-5,Rinf=1e9+5;
multiset <int> L,R;
int mn=0,shL=0,shR=0,h;
signed main(){
ios_base::sync_with_stdio(false);
cin.tie(NULL);
cout.tie(NULL);
cin>>n>>h;
L.insert(Linf);
R.insert(Rinf);
for(int i=0;i<n;i++){
cin>>arr[i];
shL-=h;shR+=h;
if(arr[i]<*L.rbegin()+shL){
mn+=*L.rbegin()+shL-arr[i];
L.extract(*L.rbegin());
L.insert(arr[i]-shL);
L.insert(arr[i]-shL);
}
else if(arr[i]>*R.begin()+shR){
mn+=arr[i]-(*R.begin()+shR);
R.extract(*R.begin());
R.insert(arr[i]-shR);
R.insert(arr[i]-shR);
}
else{
L.insert(arr[i]-shL);
R.insert(arr[i]-shR);
}
}
cout<<mn<<endl;
return 0;
}
| # | 결과 | 실행 시간 | 메모리 | 채점기 출력 |
|---|---|---|---|---|
| 결과를 불러오는 중입니다… | ||||
| # | 결과 | 실행 시간 | 메모리 | 채점기 출력 |
|---|---|---|---|---|
| 결과를 불러오는 중입니다… | ||||
| # | 결과 | 실행 시간 | 메모리 | 채점기 출력 |
|---|---|---|---|---|
| 결과를 불러오는 중입니다… | ||||
| # | 결과 | 실행 시간 | 메모리 | 채점기 출력 |
|---|---|---|---|---|
| 결과를 불러오는 중입니다… | ||||
| # | 결과 | 실행 시간 | 메모리 | 채점기 출력 |
|---|---|---|---|---|
| 결과를 불러오는 중입니다… | ||||
| # | 결과 | 실행 시간 | 메모리 | 채점기 출력 |
|---|---|---|---|---|
| 결과를 불러오는 중입니다… | ||||
| # | 결과 | 실행 시간 | 메모리 | 채점기 출력 |
|---|---|---|---|---|
| 결과를 불러오는 중입니다… | ||||
| # | 결과 | 실행 시간 | 메모리 | 채점기 출력 |
|---|---|---|---|---|
| 결과를 불러오는 중입니다… | ||||
| # | 결과 | 실행 시간 | 메모리 | 채점기 출력 |
|---|---|---|---|---|
| 결과를 불러오는 중입니다… | ||||
