Submission #938429

# Submission time Handle Problem Language Result Execution time Memory
938429 2024-03-05T06:28:33 Z vjudge1 Sure Bet (CEOI17_sure) C++17
100 / 100
89 ms 5328 KB
#include <bits/stdc++.h>

#define ff first
#define ss second
#define pb push_back
#define all(x) x.begin(),x.end()
#define rall(x) x.rbegin(),x.rend()
#define int long double

using namespace std;

//int pow(int a,int b,int m){int ans=1;while(b){if(b&1){ans=(ans*a)%m;}b>>=1;a=(a*a)%m;}return ans;}
//int binpow(int a,int b){int ans=1;while(b){if(b&1){ans=(ans*a);}b>>=1;a=(a*a);}return ans;}
  
const int N = 2e5 + 10,  inf = 1e18;

main(){
	iostream::sync_with_stdio(false);  
    cin.tie(nullptr);
    cout.tie(nullptr);
    int32_t n;
    cin >> n;
    vector <int> a(n), b(n);
    for(int i = 0; i < n; i++){
		cin >> a[i] >> b[i];
	}
	int ans = 0;
	sort(rall(a));
	sort(rall(b));
	int l = 0, r = 0, suma = 0, sumb = 0;
	while(l < n || r < n){
		if(suma < sumb && l < n){
			suma += a[l++];
		}else if(sumb < suma && r < n){
			sumb += b[r++];
		}else{
			if(l < n){
				suma += a[l++];
			}else if(r < n){
				sumb += b[r++];
			}else
				break;
		}
		ans = max(ans, min(sumb,suma) - l - r);
	}
	cout << fixed << setprecision(4) << ans;
}

Compilation message

sure.cpp:17:1: warning: ISO C++ forbids declaration of 'main' with no type [-Wreturn-type]
   17 | main(){
      | ^~~~
# Verdict Execution time Memory Grader output
1 Correct 1 ms 344 KB Output is correct
2 Correct 0 ms 344 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 1 ms 344 KB Output is correct
5 Correct 0 ms 348 KB Output is correct
6 Correct 0 ms 348 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 344 KB Output is correct
2 Correct 0 ms 344 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 1 ms 344 KB Output is correct
5 Correct 0 ms 348 KB Output is correct
6 Correct 0 ms 348 KB Output is correct
7 Correct 0 ms 348 KB Output is correct
8 Correct 1 ms 348 KB Output is correct
9 Correct 1 ms 344 KB Output is correct
10 Correct 0 ms 348 KB Output is correct
11 Correct 1 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 512 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 1 ms 344 KB Output is correct
2 Correct 0 ms 344 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 1 ms 344 KB Output is correct
5 Correct 0 ms 348 KB Output is correct
6 Correct 0 ms 348 KB Output is correct
7 Correct 0 ms 348 KB Output is correct
8 Correct 1 ms 348 KB Output is correct
9 Correct 1 ms 344 KB Output is correct
10 Correct 0 ms 348 KB Output is correct
11 Correct 1 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 512 KB Output is correct
15 Correct 1 ms 348 KB Output is correct
16 Correct 1 ms 348 KB Output is correct
17 Correct 71 ms 4872 KB Output is correct
18 Correct 74 ms 4724 KB Output is correct
19 Correct 70 ms 4956 KB Output is correct
20 Correct 72 ms 4956 KB Output is correct
21 Correct 74 ms 5124 KB Output is correct
22 Correct 69 ms 4868 KB Output is correct
23 Correct 69 ms 4748 KB Output is correct
24 Correct 72 ms 4956 KB Output is correct
25 Correct 69 ms 5156 KB Output is correct
26 Correct 89 ms 5328 KB Output is correct