Submission #907628

#TimeUsernameProblemLanguageResultExecution timeMemory
907628vjudge1Let's Win the Election (JOI22_ho_t3)C++17
10 / 100
10 ms504 KiB
#include <bits/stdc++.h>
using namespace std;

#define rep(i, a, b) for(int i = a; i < (b); ++i)
#define all(x) begin(x), end(x)
#define sz(x) (int)(x).size()
#define F first
#define S second
#define pb push_back
typedef long long ll;
typedef pair<int, int> pii;
typedef vector<int> vi;

int main() {
	cin.tie(0)->sync_with_stdio(0);
	cin.exceptions(cin.failbit);
	int n;cin>>n;
	int k;cin>>k;
	vector<pair<pair<ll,ll>,int>> bya(n);
	rep(i,0,n)cin>>bya[i].F.F>>bya[i].F.S;
	sort(all(bya));
	rep(i,0,n)bya[i].S=i;
	vector<pair<pair<ll,ll>,int>> byb = bya;
	sort(all(byb), [&](auto a, auto b){
		if(a.F.S == -1) return false;
		if(b.F.S == -1) return true;
		return a.F.S < b.F.S;
	});
	while(sz(byb) && byb.back().F.S == -1) byb.pop_back();
	// for(auto p : bya) cout<< p.F.F<<' '<<p.F.S<<' '<<p.S<<endl;
	// cout<<endl;
	// for(auto p : byb) cout<< p.F.F<<' '<<p.F.S<<' '<<p.S<<endl;
	double fast = 1e18;
	rep(u,0,min(k,sz(byb))+1){
		double time = 0;
		set<int> have;
		rep(i,0,u){
			time += (double)byb[i].F.S/(1+i);
			have.insert(byb[i].S);
		}
		int need = k-u;
		rep(i,0,n){
			if(need==0) break;
			if(have.count(i)) continue;
			time += (double)bya[i].F.F/(u+1);
			need--;
		}
		fast = min(fast, time);
	}
	cout<<fixed<<setprecision(10)<<fast<<endl;
}
#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...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...