Submission #1101897

# Submission time Handle Problem Language Result Execution time Memory
1101897 2024-10-17T07:17:43 Z Warinchai Safety (NOI18_safety) C++14
4 / 100
25 ms 3960 KB
#include<bits/stdc++.h>
using namespace std;
priority_queue<int,vector<int>,greater<int>>r;
priority_queue<int>l;
int ar[200005];
int lzl,lzr;
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;
    for(int i=1;i<=n;i++){
        if(i!=1&&ar[i]<l.top()+lzl){
            ans+=l.top()+lzl-ar[i];
            l.push(ar[i]-lzl);
            l.push(ar[i]-lzl);
            r.push(l.top()+lzl-lzr);
            l.pop();
        }else if(i!=1&&ar[i]>r.top()+lzr){
            ans+=ar[i]-r.top()-lzr;
            r.push(ar[i]-lzr);
            r.push(ar[i]-lzr);
            l.push(r.top()+lzr-lzl);
            r.pop();
        }else{
            l.push(ar[i]-lzl);
            r.push(ar[i]-lzr);
        }
        lzl-=h;
        lzr+=h;
    }
    cout<<ans;
}
# Verdict Execution time Memory Grader output
1 Correct 1 ms 340 KB Output is correct
2 Correct 1 ms 340 KB Output is correct
3 Correct 1 ms 340 KB Output is correct
4 Incorrect 1 ms 340 KB Output isn't correct
5 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 340 KB Output is correct
2 Correct 1 ms 340 KB Output is correct
3 Correct 1 ms 340 KB Output is correct
4 Correct 1 ms 340 KB Output is correct
5 Correct 1 ms 340 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 340 KB Output is correct
2 Correct 1 ms 340 KB Output is correct
3 Correct 1 ms 340 KB Output is correct
4 Incorrect 1 ms 340 KB Output isn't correct
5 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 25 ms 3960 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 340 KB Output is correct
2 Correct 1 ms 340 KB Output is correct
3 Correct 1 ms 340 KB Output is correct
4 Incorrect 1 ms 340 KB Output isn't correct
5 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 340 KB Output is correct
2 Correct 1 ms 340 KB Output is correct
3 Correct 1 ms 340 KB Output is correct
4 Incorrect 1 ms 340 KB Output isn't correct
5 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 340 KB Output is correct
2 Correct 1 ms 340 KB Output is correct
3 Correct 1 ms 340 KB Output is correct
4 Incorrect 1 ms 340 KB Output isn't correct
5 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 340 KB Output is correct
2 Correct 1 ms 340 KB Output is correct
3 Correct 1 ms 340 KB Output is correct
4 Incorrect 1 ms 340 KB Output isn't correct
5 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 340 KB Output is correct
2 Correct 1 ms 340 KB Output is correct
3 Correct 1 ms 340 KB Output is correct
4 Incorrect 1 ms 340 KB Output isn't correct
5 Halted 0 ms 0 KB -