Submission #586305

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

Compilation message (stderr)

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