Submission #1083648

#TimeUsernameProblemLanguageResultExecution timeMemory
1083648dwuyLet's Win the Election (JOI22_ho_t3)C++14
10 / 100
4 ms604 KiB
/**         - dwuy -

      />    フ
      |  _  _|
      /`ミ _x ノ
     /      |
    /   ヽ   ?
 / ̄|   | | |
 | ( ̄ヽ__ヽ_)_)
 \二つ

**/
#include <bits/stdc++.h>

#define fastIO ios_base::sync_with_stdio(false); cin.tie(NULL)
#define file(a) freopen(a".inp","r",stdin); freopen(a".out", "w",stdout)
#define fi first
#define se second
#define endl "\n"
#define len(s) (int)((s).size())
#define MASK(k)(1LL<<(k))
#define TASK "test"
#define int long long

using namespace std;

typedef tuple<int, int, int> tpiii;
typedef pair<double, double> pdd;
typedef pair<int, int> pii;
typedef long long ll;

const long long OO = 1e18;
const int MOD = 1e9 + 7;
const int INF = 1e9;
const int MX = 505;

int n, k;
pii a[MX];

int32_t main(){
    fastIO;
    //file(TASK);

    cin >> n >> k;
    for(int i=1; i<=n; i++){
        cin >> a[i].fi >> a[i].se;
        if(a[i].se == -1) a[i].se = OO;
    }
    sort(a + 1, a + 1 + n, [](const pii &a, const pii &b) -> bool {return a.se < b.se;});

    double ans = 1e18;
    double cur = 0;
    for(int i=0; i<=n; i++) if(a[i].se != OO){
        cur += i? 1.0*a[i].se/i : 0;
        vector<int> vt;
        for(int j=i+1; j<=n; j++){
            vt.push_back(a[j].fi);
        }
        sort(vt.begin(), vt.end());
        double tmp = 0;
        for(int j=0; j<k-i; j++) tmp += 1.0*vt[j]/(i + 1);
        ans = min(ans, cur + tmp);
    }   

    cout << setprecision(7) << fixed << ans << endl;

    return 0;
}




#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...