Submission #1112591

#TimeUsernameProblemLanguageResultExecution timeMemory
1112591guagua0407Potatoes and fertilizers (LMIO19_bulves)C++17
100 / 100
143 ms17344 KiB
//#pragma GCC optimize("O3") #include <bits/stdc++.h> using namespace std; #define ll long long #define int ll #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); } signed main() {_ int n; cin>>n; vector<ll> 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<ll> 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: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 + ".in").c_str(), "r", stdin);
      |     ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
bulves.cpp:14:12: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   14 |     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...