Submission #919753

#TimeUsernameProblemLanguageResultExecution timeMemory
9197538pete8Potatoes and fertilizers (LMIO19_bulves)C++17
30 / 100
77 ms9308 KiB
#include<iostream> #include<stack> #include<map> #include<vector> #include<string> #include<unordered_map> #include <queue> #include<cstring> #include<cassert> #include<limits.h> #include<cmath> #include<set> #include<algorithm> #include<bitset> #include<stack> using namespace std; #define ll long long #define f first #define endl "\n" #define s second #define pii pair<int,int> #define pppiiii pair<pii,pii> #define ppii pair<int,pii> #define all(x) x.begin(),x.end() #define pb push_back #define mp make_pair #define lb lower_bound #define ub upper_bound #define fastio ios::sync_with_stdio(false);cin.tie(NULL); #pragma GCC optimize ("03,unroll-loops") #define int long long const int mod=1e9+7,mxn=3e5+5,lg=30,inf=1e18,minf=-1e9,Mxn=100000; int n,k; void setIO(string name){ ios_base::sync_with_stdio(0); cin.tie(0); freopen((name+".in").c_str(),"r",stdin); freopen((name+".out").c_str(),"w",stdout); } int val[mxn+10]; int32_t main(){ fastio int n;cin>>n; for(int i=1;i<=n;i++){ int a,b;cin>>a>>b; val[i]=val[i-1]+a-b; } priority_queue<int>pq; int ans=0; for(int i=1;i<=n;i++){ if(val[i]<0)ans-=val[i],val[i]=0; ans+=val[i]; pq.push(val[i]); pq.push(val[i]); pq.pop(); } while(!pq.empty())ans-=min(val[n],pq.top()),pq.pop(); cout<<ans; return 0; }

Compilation message (stderr)

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