Submission #945918

# Submission time Handle Problem Language Result Execution time Memory
945918 2024-03-14T08:46:25 Z Warinchai Safety (NOI18_safety) C++14
4 / 100
26 ms 3776 KB
#include<bits/stdc++.h>
using namespace std;
int ar[200005];
priority_queue<int>pql;
priority_queue<int,vector<int>,greater<int>>pqr;
int main(){
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    int n,h;cin>>n>>h;
    for(int i=1;i<=n;i++)cin>>ar[i];
    int ans=0;
    int lzl=0;
    int lzr=0;
    for(int i=1;i<=n;i++){
        if(i!=1&&(ar[i]<pql.top()+lzl)){
            ans+=pql.top()+lzl-ar[i];
            pql.push(ar[i]-lzl);
            pql.push(ar[i]-lzl);
            pqr.push(pql.top()+lzl-lzr);
            pql.pop();
        }else if(i!=1&&(ar[i]>pqr.top()+lzr)){
            ans+=ar[i]-(pqr.top()+lzr);
            pqr.push(ar[i]-lzr);
            pqr.push(ar[i]-lzr);
            pql.push(pqr.top()+lzr-lzl);
            pqr.pop();
        }else{
            pql.push(ar[i]-lzl);
            pqr.push(ar[i]-lzr);
        }
        lzl-=h;
        lzr+=h;
        ///cout<<ans<<" "<<pql.top()+lzl<<' '<<pqr.top()+lzr<<"\n";
    }
    cout<<ans;
}
# Verdict Execution time Memory Grader output
1 Correct 1 ms 344 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Incorrect 1 ms 348 KB Output isn't correct
5 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 344 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 600 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 1 ms 348 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Incorrect 0 ms 348 KB Output isn't correct
5 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 26 ms 3776 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 344 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Incorrect 1 ms 348 KB Output isn't correct
5 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 344 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Incorrect 1 ms 348 KB Output isn't correct
5 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 344 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Incorrect 1 ms 348 KB Output isn't correct
5 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 344 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Incorrect 1 ms 348 KB Output isn't correct
5 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 344 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Incorrect 1 ms 348 KB Output isn't correct
5 Halted 0 ms 0 KB -