Submission #559261

#TimeUsernameProblemLanguageResultExecution timeMemory
559261M_WSafety (NOI18_safety)C++14
100 / 100
56 ms5388 KiB
#include <bits/stdc++.h> using namespace std; int main(){ long long N, H; scanf("%lld %lld", &N, &H); long long ymin = 0, shift = 0; priority_queue<long long> L; priority_queue<long long, vector<long long>, greater<long long>> R; long long x; scanf("%lld", &x); L.push(x); R.push(x); for(long long i = 1; i < N; i++){ scanf("%lld", &x); shift += H; long long left = L.top() - shift; long long right = R.top() + shift; if(x < left){ ymin += abs(left - x); R.push(left - shift); L.pop(); L.push(x + shift); L.push(x + shift); } else if(x > right){ ymin += abs(right - x); L.push(right + shift); R.pop(); R.push(x - shift); R.push(x - shift); } else{ L.push(x + shift); R.push(x - shift); } } printf("%lld", ymin); }

Compilation message (stderr)

safety.cpp: In function 'int main()':
safety.cpp:5:7: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
    5 |  scanf("%lld %lld", &N, &H);
      |  ~~~~~^~~~~~~~~~~~~~~~~~~~~
safety.cpp:12:7: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   12 |  scanf("%lld", &x);
      |  ~~~~~^~~~~~~~~~~~
safety.cpp:15:8: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   15 |   scanf("%lld", &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...