답안 #1000718

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
1000718 2024-06-18T07:35:53 Z vjudge1 Safety (NOI18_safety) C++17
18 / 100
161 ms 21268 KB
#include<bits/stdc++.h>
using namespace std;
#define ll long long

int a[200100];

void solve(){
    int n, h;
    cin>>n>>h;
    for(int i=1; i<=n; i++){
        cin>>a[i];
    }
    multiset<ll> ql, qr;
    ql.insert(a[1]);
    qr.insert(a[1]);
    ll ans = 0;
    for(int i=2; i<=n; i++){
        ll add = h * (i - 1);
        ll l=*ql.rbegin()-add, r=*qr.begin()+add;
        ll t = a[i];
        if(l <= t and t <= r){
            ql.insert(t+add);
            qr.insert(t-add);
        }
        else if(l > t){
            ans += l-t;
            qr.insert(l-add);
            ql.erase(ql.find(l + add));
            ql.insert(t+add);
            ql.insert(t+add);
        }
        else if(r < t){
            ans += t - r;
            ql.insert(r+add);
            qr.erase(qr.find(r - add));
            qr.insert(t-add);
            qr.insert(t-add);
        }
    } 
    cout<<ans<<'\n';
}



int main(){
    solve();
}
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 344 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 0 ms 452 KB Output is correct
4 Incorrect 0 ms 348 KB Output isn't correct
5 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 348 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 0 ms 348 KB Output is correct
5 Correct 0 ms 348 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 348 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 0 ms 348 KB Output is correct
5 Correct 0 ms 348 KB Output is correct
6 Correct 0 ms 348 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 100 ms 14424 KB Output is correct
2 Correct 141 ms 20308 KB Output is correct
3 Correct 161 ms 21268 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 344 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 0 ms 452 KB Output is correct
4 Incorrect 0 ms 348 KB Output isn't correct
5 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 344 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 0 ms 452 KB Output is correct
4 Incorrect 0 ms 348 KB Output isn't correct
5 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 344 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 0 ms 452 KB Output is correct
4 Incorrect 0 ms 348 KB Output isn't correct
5 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 344 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 0 ms 452 KB Output is correct
4 Incorrect 0 ms 348 KB Output isn't correct
5 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 344 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 0 ms 452 KB Output is correct
4 Incorrect 0 ms 348 KB Output isn't correct
5 Halted 0 ms 0 KB -