Submission #470093

#TimeUsernameProblemLanguageResultExecution timeMemory
470093biggSafety (NOI18_safety)C++14
100 / 100
285 ms19060 KiB
#include<bits/stdc++.h> using namespace std; typedef long long ll; multiset<ll> sl, sr; ll suml, sumr; int n; ll h; int main(){ scanf("%d %lld", &n, &h); ll ans = 0; for(int i = 1; i <= n; i++){ ll k; scanf("%lld", &k); if(i == 1){ sl.insert(k); sr.insert(k); continue; } suml-=h; sumr+=h; auto it = sl.end(); it--; ll esq = *it; ll dir = *sr.begin(); esq += suml; dir += sumr; if(k < esq){ ans += abs(esq -k); sl.insert(k - suml); sl.insert(k - suml); }else if(k > dir){ ans += abs(dir -k); sr.insert(k - sumr); sr.insert(k - sumr); }else{ sl.insert(k - suml); sr.insert(k - sumr); } it = sl.end(); it--; esq = *it; dir = *sr.begin(); esq += suml; dir += sumr; if(sl.size() == sr.size()) continue; if(sl.size() > sr.size()){ sr.insert(esq - sumr); sl.erase(it); }else{ sl.insert(dir - suml); sr.erase(sr.begin()); } } printf("%lld\n", ans); }

Compilation message (stderr)

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