Submission #208122

#TimeUsernameProblemLanguageResultExecution timeMemory
208122DystoriaXSafety (NOI18_safety)C++14
100 / 100
85 ms5528 KiB
#include <bits/stdc++.h>

using namespace std;

int n, h;
int x;
long long ans;
priority_queue<long long> lf;
priority_queue<long long, vector<long long>, greater<long long> > rg;

int main(){
    scanf("%d%d", &n, &h);

    //First input
    scanf("%d", &x);
    lf.push(x), rg.push(x);

    for(int i = 1; i < n; i++){
        long long lazy = 1LL * h * i;

        scanf("%d", &x);

        if(x < lf.top() - lazy){
            ans += lf.top() - lazy - x;
            rg.push(lf.top() - (lazy << 1));
            lf.push(x + lazy);
            lf.push(x + lazy);
            lf.pop();
        } else if (rg.top() + lazy < x){
            ans += x - (rg.top() + lazy);
            lf.push(rg.top() + (lazy << 1));
            rg.push(x - lazy);
            rg.push(x - lazy);
            rg.pop();
        } else {
            lf.push(x + lazy);
            rg.push(x - lazy);
        }
    }

    printf("%lld\n", ans);
    
    return 0;
}

Compilation message (stderr)

safety.cpp: In function 'int main()':
safety.cpp:12:10: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
     scanf("%d%d", &n, &h);
     ~~~~~^~~~~~~~~~~~~~~~
safety.cpp:15:10: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
     scanf("%d", &x);
     ~~~~~^~~~~~~~~~
safety.cpp:21:14: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
         scanf("%d", &x);
         ~~~~~^~~~~~~~~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...