Submission #1187836

#TimeUsernameProblemLanguageResultExecution timeMemory
1187836sitingfakePotatoes and fertilizers (LMIO19_bulves)C++20
0 / 100
0 ms320 KiB
#include<bits/stdc++.h> using namespace std; // define #define execute cerr << "Time elapsed: " << (1.0 * clock() / CLOCKS_PER_SEC) << "s"; #define ll long long #define ld long double #define ii pair<int,int> #define se second #define fi first #define iii pair<int,ii> #define all(v) v.begin(),v.end() #define bit(x,i) (((x)>>(i))&1LL) #define flip(x,i) ((x)^(1LL<<(i))) #define ms(d,x) memset(d,x,sizeof(d)) #define sitingfake 1 #define orz 1 template<typename T> bool maximize(T &a, const T &b) { if(a < b) {a = b; return 1;} return 0; } template<typename T> bool minimize(T &a, const T &b) { if(a > b) {a = b;return 1;} return 0; } //constant const ll mod = 1e9+7; const long long linf = 4557430888798830399; const int inf = 1061109567; const int maxarr = 1e6+5; const int dx[] = {0,1,-1,0}; const int dy[] = {1,0,0,-1}; //code const int maxn = 5e5 + 7; int n; ll pre[maxn]; void solve(void) { cin >> n; for(int i=1;i<=n;i++) { int x , y; cin >> x >> y; pre[i] = pre[i-1] + x - y; } ll ans = 0; priority_queue<ll> q; for(int i=1;i<=n;i++) { ans += abs(pre[i]); if(pre[i] < 0) pre[i] = 0; q.push(pre[i]); q.push(pre[i]); q.pop(); } while(!q.empty()) { ans -= q.top(); q.pop(); } cout << ans; } signed main() { ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0); #define task "" if(fopen(task".inp","r")) { freopen(task".inp","r",stdin); freopen(task".out","w",stdout); } int tc; tc = 1; while(tc--) solve(); //execute; } /** **/

Compilation message (stderr)

bulves.cpp: In function 'int main()':
bulves.cpp:87:15: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   87 |        freopen(task".inp","r",stdin);
      |        ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~
bulves.cpp:88:15: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   88 |        freopen(task".out","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...