Submission #285796

#TimeUsernameProblemLanguageResultExecution timeMemory
285796tbzardSafety (NOI18_safety)C++14
100 / 100
76 ms6284 KiB
#include <bits/stdc++.h> using namespace std; typedef long long ll; typedef pair<int, int> pii; typedef pair<int, pii> pipii; typedef pair<pii, int> piipi; typedef pair<pii, pii> piipii; #define mp make_pair #define fi first #define se second #define all(a) (a).begin(), (a).end() #define sz(a) (int)(a).size() #define eb emplace_back int a[200005]; int main(){ int n, h; scanf("%d%d", &n, &h); for(int i=1;i<=n;i++) scanf("%d", &a[i]); priority_queue<ll> L; priority_queue<ll, vector<ll>, greater<ll> > R; ll ans = 0; ll shift_L = 0, shift_R = 0; L.push(a[1]); R.push(a[1]); for(int i=2;i<=n;i++){ shift_L -= h; shift_R += h; ll mn = L.top() + shift_L; ll mx = R.top() + shift_R; if(mn <= a[i] && a[i] <= mx){ L.push(a[i]-shift_L); R.push(a[i]-shift_R); } else if(a[i] < mn){ ans += mn-a[i]; L.pop(); L.push(a[i]-shift_L); L.push(a[i]-shift_L); R.push(mn-shift_R); } else{ ans += a[i]-mx; R.pop(); R.push(a[i]-shift_R); R.push(a[i]-shift_R); L.push(mx-shift_L); } } printf("%lld\n", ans); }

Compilation message (stderr)

safety.cpp: In function 'int main()':
safety.cpp:20:10: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
   20 |     scanf("%d%d", &n, &h);
      |     ~~~~~^~~~~~~~~~~~~~~~
safety.cpp:21:32: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
   21 |     for(int i=1;i<=n;i++) scanf("%d", &a[i]);
      |                           ~~~~~^~~~~~~~~~~~~
#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...