Submission #385783

#TimeUsernameProblemLanguageResultExecution timeMemory
385783LucaDantasSafety (NOI18_safety)C++17
18 / 100
253 ms20468 KiB
#include <cstdio> #include <set> int difl, difr; // lazy std::multiset<int> l, r; long long ans = 0; void sl(int i) { int passar = *r.begin() + difr; r.erase(r.begin()); ans += (passar - (*l.rbegin() + difl)) * (-i + (int)l.size()); l.insert(passar - difl); } void sr(int i) { int passar = *l.rbegin() + difl; l.erase(--l.end()); ans -= (passar - (*l.rbegin() + difl)) * (-i + (int)l.size()); r.insert(passar - difr); } int abs(int a) { return a < 0 ? -a : a; } int main() { int n, k; scanf("%d %d", &n, &k); int center = 0; for(int i = 1; i <= n; i++) { int a; scanf("%d", &a); if(l.size()) ans += abs(a - *l.rbegin() - difl); if(!l.size() || a <= *l.rbegin() + difl) l.insert(a - difl), l.insert(a - difl); else r.insert(a - difr), r.insert(a - difr); while((int)l.size() > i) sr(i); while((int)r.size() > i) sl(i); difr += k; difl -= k; } printf("%lld\n", ans); }

Compilation message (stderr)

safety.cpp: In function 'int main()':
safety.cpp:28:6: warning: unused variable 'center' [-Wunused-variable]
   28 |  int center = 0;
      |      ^~~~~~
safety.cpp:27:17: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
   27 |  int n, k; scanf("%d %d", &n, &k);
      |            ~~~~~^~~~~~~~~~~~~~~~~
safety.cpp:30:15: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
   30 |   int a; scanf("%d", &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...