Submission #586390

#TimeUsernameProblemLanguageResultExecution timeMemory
586390hibikiSafety (NOI18_safety)C++11
100 / 100
58 ms4684 KiB
#include<bits/stdc++.h> using namespace std; long long n,h; long long a; long long y_min = 0, shift; priority_queue<long long> l, r; int main() { scanf("%lld %lld",&n,&h); scanf("%lld",&a); l.push(a); r.push(-a); for(int i = 1; i < n; i++) { scanf("%lld",&a); shift += h; long long curl = l.top() - shift; long long curr = - r.top() + shift; if(curl <= a && a <= curr) { l.push(a + shift); r.push(-(a - shift)); } else if(a < curl) { y_min += curl - a; r.push(-(curl - shift)); l.pop(); l.push(a + shift); l.push(a + shift); } else if(curr < a) { y_min += a - curr; l.push(curr + shift); r.pop(); r.push(-(a - shift)); r.push(-(a - shift)); } } printf("%lld\n",y_min); }

Compilation message (stderr)

safety.cpp: In function 'int main()':
safety.cpp:11:10: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   11 |     scanf("%lld %lld",&n,&h);
      |     ~~~~~^~~~~~~~~~~~~~~~~~~
safety.cpp:12:10: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   12 |     scanf("%lld",&a);
      |     ~~~~~^~~~~~~~~~~
safety.cpp:17:14: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   17 |         scanf("%lld",&a);
      |         ~~~~~^~~~~~~~~~~
#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...