Submission #534209

# Submission time Handle Problem Language Result Execution time Memory
534209 2022-03-08T02:15:18 Z PikaQ Let's Win the Election (JOI22_ho_t3) C++17
10 / 100
4 ms 368 KB
#include<bits/stdc++.h>
#define forn(i,n) for(int i = 0;i < (n);i++)
#define Forn(i,n) for(int i = 1;i <= (n);i++)
#define all(p) p.begin(),p.end()
#define pb push_back
#define F first
#define S second
#define rz resize
#define sz(x) x.size()
#define int long long
#define vi vector<int>
#define pii pair<int,int>
using namespace std;
const int N = 2e5+9;
const int INF = 500 * 1000 +9;
 
int n,k;
vector<pii> a;
 
bool cmp(pii x,pii y){
	return (x.F < y.F || (x.F == y.F && x.S > y.S));
}
 
void solve(){
	cin >> n >> k;
	a.rz(n);
	forn(i,n){ 
		cin >> a[i].S >> a[i].F;
		if(a[i].F == -1) a[i].F = INF;
	}
	sort(all(a),cmp);
	if(n == k){
		int sum = 0;
		forn(i,n){
			sum += a[i].S;
		}
		double res = 0;
		double ans = INF;
		for(int i = 0;i <= n;i++){
			if(i) res += (double) a[i-1].F/(i);
			if(i) sum -= a[i-1].S;
			ans = min(ans,(double)sum/(i+1) + res);
		}
		cout << ans << '\n';
		return;
	}
	double ans = INF;
	double res = 0;
	for(int i = 0;i <= k;i++){
		if(i) {
			res += (double)a[i-1].F/(i);
		}
		vi b;
		for(int j = i;j < n;j++){
			b.pb(a[j].S);
		}
		sort(all(b));
		int tr = 0;
		for(int r = 0;r < k-i;r++){
			tr += b[r];
		}
		//cout << res << ' ' << tr << ' ' << (double)tr/(i+1) << '\n';
		ans = min(ans,(double) res + (double)tr / (i+1));
	}
	cout << ans << '\n';
}
 
signed main(){
	cin.tie(NULL);
	cout.tie(NULL);
	ios_base::sync_with_stdio(0);
	cout << fixed << setprecision(4);
	solve();
	return 0;
}
# Verdict Execution time Memory Grader output
1 Correct 1 ms 204 KB Output is correct
2 Correct 1 ms 204 KB Output is correct
3 Correct 1 ms 204 KB Output is correct
4 Correct 1 ms 204 KB Output is correct
5 Correct 1 ms 332 KB Output is correct
6 Correct 2 ms 332 KB Output is correct
7 Correct 2 ms 204 KB Output is correct
8 Correct 2 ms 204 KB Output is correct
9 Correct 1 ms 204 KB Output is correct
10 Correct 2 ms 332 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 204 KB Output is correct
2 Correct 1 ms 204 KB Output is correct
3 Correct 1 ms 204 KB Output is correct
4 Correct 1 ms 204 KB Output is correct
5 Correct 1 ms 332 KB Output is correct
6 Correct 2 ms 332 KB Output is correct
7 Correct 2 ms 204 KB Output is correct
8 Correct 2 ms 204 KB Output is correct
9 Correct 1 ms 204 KB Output is correct
10 Correct 2 ms 332 KB Output is correct
11 Correct 1 ms 204 KB Output is correct
12 Correct 2 ms 312 KB Output is correct
13 Correct 3 ms 332 KB Output is correct
14 Correct 3 ms 204 KB Output is correct
15 Correct 3 ms 204 KB Output is correct
16 Correct 4 ms 308 KB Output is correct
17 Correct 3 ms 328 KB Output is correct
18 Correct 1 ms 204 KB Output is correct
19 Correct 1 ms 204 KB Output is correct
20 Correct 1 ms 204 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 204 KB Output is correct
2 Correct 1 ms 204 KB Output is correct
3 Correct 1 ms 204 KB Output is correct
4 Correct 1 ms 368 KB Output is correct
5 Correct 1 ms 204 KB Output is correct
6 Correct 1 ms 204 KB Output is correct
7 Correct 1 ms 204 KB Output is correct
8 Correct 1 ms 204 KB Output is correct
9 Incorrect 1 ms 304 KB Output isn't correct
10 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 204 KB Output is correct
2 Correct 1 ms 204 KB Output is correct
3 Correct 1 ms 204 KB Output is correct
4 Correct 1 ms 368 KB Output is correct
5 Correct 1 ms 204 KB Output is correct
6 Correct 1 ms 204 KB Output is correct
7 Correct 1 ms 204 KB Output is correct
8 Correct 1 ms 204 KB Output is correct
9 Incorrect 1 ms 304 KB Output isn't correct
10 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 204 KB Output is correct
2 Correct 1 ms 204 KB Output is correct
3 Correct 1 ms 204 KB Output is correct
4 Correct 1 ms 368 KB Output is correct
5 Correct 1 ms 204 KB Output is correct
6 Correct 1 ms 204 KB Output is correct
7 Correct 1 ms 204 KB Output is correct
8 Correct 1 ms 204 KB Output is correct
9 Incorrect 1 ms 304 KB Output isn't correct
10 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 1 ms 204 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 204 KB Output is correct
2 Correct 1 ms 204 KB Output is correct
3 Correct 1 ms 204 KB Output is correct
4 Correct 1 ms 204 KB Output is correct
5 Correct 1 ms 332 KB Output is correct
6 Correct 2 ms 332 KB Output is correct
7 Correct 2 ms 204 KB Output is correct
8 Correct 2 ms 204 KB Output is correct
9 Correct 1 ms 204 KB Output is correct
10 Correct 2 ms 332 KB Output is correct
11 Correct 1 ms 204 KB Output is correct
12 Correct 2 ms 312 KB Output is correct
13 Correct 3 ms 332 KB Output is correct
14 Correct 3 ms 204 KB Output is correct
15 Correct 3 ms 204 KB Output is correct
16 Correct 4 ms 308 KB Output is correct
17 Correct 3 ms 328 KB Output is correct
18 Correct 1 ms 204 KB Output is correct
19 Correct 1 ms 204 KB Output is correct
20 Correct 1 ms 204 KB Output is correct
21 Correct 1 ms 204 KB Output is correct
22 Correct 1 ms 204 KB Output is correct
23 Correct 1 ms 204 KB Output is correct
24 Correct 1 ms 368 KB Output is correct
25 Correct 1 ms 204 KB Output is correct
26 Correct 1 ms 204 KB Output is correct
27 Correct 1 ms 204 KB Output is correct
28 Correct 1 ms 204 KB Output is correct
29 Incorrect 1 ms 304 KB Output isn't correct
30 Halted 0 ms 0 KB -