Submission #938272

# Submission time Handle Problem Language Result Execution time Memory
938272 2024-03-05T03:59:00 Z vjudge1 Sure Bet (CEOI17_sure) C++17
100 / 100
67 ms 3772 KB
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#define pii pair<int,int>
using namespace __gnu_pbds;
using namespace std;
#define pb push_back
#define all(x) x.begin(),x.end()
#define rall(x) x.rbegin(),x.rend()
#define f first
#define int double
#define s second
#define pii pair<int,int>
template<class T>bool umax(T &a,T b){if(a<b){a=b;return true;}return false;}
template<class T>bool umin(T &a,T b){if(b<a){a=b;return true;}return false;}
typedef tree<int, null_type, less_equal<int>, rb_tree_tag,
	tree_order_statistics_node_update> ordered_set;
const int N=3e5 + 5	;
const int inf = 1e17 + 7;
const int mod = 998244353;

long long binpow(long long n, long long m){
	
	if(m == 0)return 1;
	else if(m % 2 == 0){
		long long sum = binpow(n,m/2);
		return sum * sum;
	}
	else{
		return binpow(n,m-1)*n;
	}

}

void solve(){
	
	int n,m,k;
	
	cin>>n;
	
	vector<int>l,r;
	
	for(int i = 0;i<n;i++){
		int a,b;
		cin>>a>>b;
		l.pb(a);
		r.pb(b);
	}
	
	sort(rall(l));
	sort(rall(r));
	
	int i = 0, j = 0;
	
	int ans = 0;
	int sum1 = 0, sum2 = 0;
	int cnt = 0;
	
	while(true){
		if(sum1-cnt<=sum2-cnt){
			if(i == n)break;
			sum1 += l[i];
			cnt += 1;
			i += 1;
		}
		else {
			if(j == n)break;
			sum2 += r[j];
			cnt += 1;
			j += 1;
		}
		
		umax(ans,min(sum1-cnt,sum2-cnt));
		
	}
	
	printf("%.4lf",(double)ans);
	
}

signed main()
{
//	freopen("seq.in", "r", stdin);
//  freopen("seq.out", "w", stdout);
	ios_base::sync_with_stdio(0);cin.tie(NULL);cout.tie(NULL);
	int tt=1;//cin>>tt>>n;
	while(tt--)solve();

}

Compilation message

sure.cpp: In function 'void solve()':
sure.cpp:37:8: warning: unused variable 'm' [-Wunused-variable]
   37 |  int n,m,k;
      |        ^
sure.cpp:37:10: warning: unused variable 'k' [-Wunused-variable]
   37 |  int n,m,k;
      |          ^
# Verdict Execution time Memory Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 0 ms 348 KB Output is correct
5 Correct 0 ms 348 KB Output is correct
6 Correct 1 ms 344 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 0 ms 348 KB Output is correct
5 Correct 0 ms 348 KB Output is correct
6 Correct 1 ms 344 KB Output is correct
7 Correct 0 ms 344 KB Output is correct
8 Correct 1 ms 348 KB Output is correct
9 Correct 0 ms 348 KB Output is correct
10 Correct 0 ms 348 KB Output is correct
11 Correct 0 ms 348 KB Output is correct
12 Correct 1 ms 348 KB Output is correct
13 Correct 1 ms 348 KB Output is correct
14 Correct 1 ms 348 KB Output is correct
15 Correct 1 ms 348 KB Output is correct
16 Correct 1 ms 348 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 0 ms 348 KB Output is correct
5 Correct 0 ms 348 KB Output is correct
6 Correct 1 ms 344 KB Output is correct
7 Correct 0 ms 344 KB Output is correct
8 Correct 1 ms 348 KB Output is correct
9 Correct 0 ms 348 KB Output is correct
10 Correct 0 ms 348 KB Output is correct
11 Correct 0 ms 348 KB Output is correct
12 Correct 1 ms 348 KB Output is correct
13 Correct 1 ms 348 KB Output is correct
14 Correct 1 ms 348 KB Output is correct
15 Correct 1 ms 348 KB Output is correct
16 Correct 1 ms 348 KB Output is correct
17 Correct 57 ms 1988 KB Output is correct
18 Correct 57 ms 3516 KB Output is correct
19 Correct 57 ms 3520 KB Output is correct
20 Correct 57 ms 3516 KB Output is correct
21 Correct 60 ms 3772 KB Output is correct
22 Correct 57 ms 3520 KB Output is correct
23 Correct 62 ms 3748 KB Output is correct
24 Correct 67 ms 3536 KB Output is correct
25 Correct 57 ms 3516 KB Output is correct
26 Correct 65 ms 3772 KB Output is correct