Submission #919755

# Submission time Handle Problem Language Result Execution time Memory
919755 2024-02-01T15:27:01 Z 8pete8 Potatoes and fertilizers (LMIO19_bulves) C++17
100 / 100
171 ms 16856 KB
#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=5e5+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

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 time Memory Grader output
1 Correct 1 ms 344 KB Output is correct
2 Correct 1 ms 348 KB Output is correct
3 Correct 1 ms 344 KB Output is correct
4 Correct 11 ms 3292 KB Output is correct
5 Correct 23 ms 3800 KB Output is correct
6 Correct 76 ms 4856 KB Output is correct
7 Correct 101 ms 11720 KB Output is correct
8 Correct 138 ms 15056 KB Output is correct
9 Correct 103 ms 13420 KB Output is correct
10 Correct 87 ms 11720 KB Output is correct
11 Correct 91 ms 12492 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 344 KB Output is correct
2 Correct 1 ms 348 KB Output is correct
3 Correct 1 ms 344 KB Output is correct
4 Correct 11 ms 3292 KB Output is correct
5 Correct 23 ms 3800 KB Output is correct
6 Correct 76 ms 4856 KB Output is correct
7 Correct 101 ms 11720 KB Output is correct
8 Correct 138 ms 15056 KB Output is correct
9 Correct 103 ms 13420 KB Output is correct
10 Correct 87 ms 11720 KB Output is correct
11 Correct 91 ms 12492 KB Output is correct
12 Correct 43 ms 5380 KB Output is correct
13 Correct 90 ms 11100 KB Output is correct
14 Correct 112 ms 16856 KB Output is correct
15 Correct 136 ms 15276 KB Output is correct
16 Correct 147 ms 13656 KB Output is correct
17 Correct 85 ms 12488 KB Output is correct
18 Correct 1 ms 344 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 344 KB Output is correct
2 Correct 1 ms 348 KB Output is correct
3 Correct 1 ms 344 KB Output is correct
4 Correct 0 ms 344 KB Output is correct
5 Correct 0 ms 344 KB Output is correct
6 Correct 1 ms 348 KB Output is correct
7 Correct 1 ms 344 KB Output is correct
8 Correct 1 ms 344 KB Output is correct
9 Correct 1 ms 348 KB Output is correct
10 Correct 1 ms 344 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 344 KB Output is correct
2 Correct 1 ms 348 KB Output is correct
3 Correct 1 ms 344 KB Output is correct
4 Correct 0 ms 344 KB Output is correct
5 Correct 0 ms 344 KB Output is correct
6 Correct 1 ms 348 KB Output is correct
7 Correct 1 ms 344 KB Output is correct
8 Correct 1 ms 344 KB Output is correct
9 Correct 1 ms 348 KB Output is correct
10 Correct 1 ms 344 KB Output is correct
11 Correct 1 ms 344 KB Output is correct
12 Correct 1 ms 344 KB Output is correct
13 Correct 1 ms 344 KB Output is correct
14 Correct 1 ms 348 KB Output is correct
15 Correct 1 ms 600 KB Output is correct
16 Correct 1 ms 344 KB Output is correct
17 Correct 1 ms 344 KB Output is correct
18 Correct 1 ms 344 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 344 KB Output is correct
2 Correct 1 ms 348 KB Output is correct
3 Correct 1 ms 344 KB Output is correct
4 Correct 0 ms 344 KB Output is correct
5 Correct 0 ms 344 KB Output is correct
6 Correct 1 ms 348 KB Output is correct
7 Correct 1 ms 344 KB Output is correct
8 Correct 1 ms 344 KB Output is correct
9 Correct 1 ms 348 KB Output is correct
10 Correct 1 ms 344 KB Output is correct
11 Correct 11 ms 3292 KB Output is correct
12 Correct 23 ms 3800 KB Output is correct
13 Correct 76 ms 4856 KB Output is correct
14 Correct 101 ms 11720 KB Output is correct
15 Correct 138 ms 15056 KB Output is correct
16 Correct 103 ms 13420 KB Output is correct
17 Correct 87 ms 11720 KB Output is correct
18 Correct 91 ms 12492 KB Output is correct
19 Correct 43 ms 5380 KB Output is correct
20 Correct 90 ms 11100 KB Output is correct
21 Correct 112 ms 16856 KB Output is correct
22 Correct 136 ms 15276 KB Output is correct
23 Correct 147 ms 13656 KB Output is correct
24 Correct 85 ms 12488 KB Output is correct
25 Correct 1 ms 344 KB Output is correct
26 Correct 1 ms 344 KB Output is correct
27 Correct 1 ms 348 KB Output is correct
28 Correct 1 ms 600 KB Output is correct
29 Correct 1 ms 344 KB Output is correct
30 Correct 1 ms 344 KB Output is correct
31 Correct 1 ms 344 KB Output is correct
32 Correct 1 ms 344 KB Output is correct
33 Correct 38 ms 5360 KB Output is correct
34 Correct 96 ms 12876 KB Output is correct
35 Correct 171 ms 16356 KB Output is correct
36 Correct 160 ms 14056 KB Output is correct
37 Correct 140 ms 13836 KB Output is correct
38 Correct 156 ms 16696 KB Output is correct
39 Correct 105 ms 11464 KB Output is correct
40 Correct 115 ms 12240 KB Output is correct
41 Correct 88 ms 10852 KB Output is correct
42 Correct 90 ms 11236 KB Output is correct
43 Correct 91 ms 11204 KB Output is correct
44 Correct 88 ms 11332 KB Output is correct
45 Correct 150 ms 15384 KB Output is correct
46 Correct 118 ms 12228 KB Output is correct
47 Correct 104 ms 11088 KB Output is correct