Submission #331343

#TimeUsernameProblemLanguageResultExecution timeMemory
331343NsonPotatoes and fertilizers (LMIO19_bulves)C++14
0 / 100
17 ms748 KiB
#include <bits/stdc++.h> using namespace std; using ll = long long; int main() { int n; scanf("%d", &n); multiset<ll> s; ll m = 0, b = 0; // s.insert(0); auto can_rem = [&]() { if(s.empty()) return false; if(m <= 0) return false; return true; if(*prev(s.end()) < 0) return false; if((int)s.size() >= 2 and *prev(prev(s.end())) >= 0) return true; return false; }; auto smooth = [&]() { while(can_rem()) { m--; b += *prev(s.end()); s.erase(prev(s.end())); } }; ll d = 0; for(int i = 0; i < n; i++) { int aa, bb; scanf("%d %d", &aa, &bb); aa -= bb; d += aa; if(d >= 0) { s.insert(d); s.insert(d); b -= d; m += 1; } else { m += 1; b -= d; } smooth(); // while(!s.empty() and *s.begin() < 0) s.erase(s.begin()); } // smooth(); while(0 and !s.empty() and *prev(s.end()) > d) { m--; b += *prev(s.end()); s.erase(prev(s.end())); } printf("%lld\n", d * m + b); }

Compilation message (stderr)

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