Submission #1112588

#TimeUsernameProblemLanguageResultExecution timeMemory
1112588guagua0407Potatoes and fertilizers (LMIO19_bulves)C++17
30 / 100
75 ms12368 KiB
//#pragma GCC optimize("O3") #include <bits/stdc++.h> using namespace std; #define ll long long #define pii pair<int,int> #define f first #define s second #define all(x) x.begin(),x.end() #define _ ios::sync_with_stdio(0); cin.tie(0); cout.tie(0); void setIO(string s) { freopen((s + ".in").c_str(), "r", stdin); freopen((s + ".out").c_str(), "w", stdout); } int main() {_ int n; cin>>n; vector<int> dif(n+1); for(int i=1;i<=n;i++){ int a,b; cin>>a>>b; dif[i]=dif[i-1]+a-b; } priority_queue<int> pq; pq.push(0); ll ans=0; for(int i=1;i<=n;i++){ if(dif[i]<0){ ans-=dif[i]; dif[i]=0; } pq.push(dif[i]); if(pq.top()>dif[i]){ pq.push(dif[i]); ans+=pq.top()-dif[i]; pq.pop(); } } int cnt=1; while(pq.top()>dif[n]){ int r=pq.top(); pq.pop(); ans+=1ll*cnt*(r-max(dif[n],pq.top())); cnt++; } cout<<ans<<'\n'; return 0; } //maybe its multiset not set

Compilation message (stderr)

bulves.cpp: In function 'void setIO(std::string)':
bulves.cpp:12:12: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   12 |     freopen((s + ".in").c_str(), "r", stdin);
      |     ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
bulves.cpp:13:12: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   13 |     freopen((s + ".out").c_str(), "w", stdout);
      |     ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
#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...