제출 #1141530

#제출 시각아이디문제언어결과실행 시간메모리
1141530ackhavaLet's Win the Election (JOI22_ho_t3)C++20
23 / 100
2596 ms436 KiB
#include <bits/stdc++.h>
#define REP(v, i, j) for (int v = i; v != j; v++)
#define FORI(v) for (auto i : v)
#define FORJ(v) for (auto j : v)

#define OUT(v, a) \
    FORI(v)       \
    cout << i << a;
#define OUTS(v, a, b)      \
    cout << v.size() << a; \
    OUT(v, b)
#define in(a, n) \
    REP(i, 0, n) \
    cin >> a[i];

#define SORT(v) sort(begin(v), end(v))
#define REV(v) reverse(begin(v), end(v))
#define MEMSET(m) memset(m, -1, sizeof m)

#define pb push_back
#define fi first
#define se second

#define detachIO                      \
    ios_base::sync_with_stdio(false); \
    cin.tie(0);                       \
    cout.tie(0);
    
using namespace std;

template<typename _Tp, typename _Alloc = std::allocator<_Tp> >
bool operator==(const vector<_Tp, _Alloc>& __x, const vector<_Tp, _Alloc>& __y) {
    if(__x.size() != __y.size()) return false;
    return std::equal(__x.begin(), __x.end(), __y.begin());
}


typedef pair<int, int> pii;
typedef pair<pii, int> piii;
typedef pair<pii, pii> piiii;

const int MOD = 1e9+7;

struct modint {
    long long val;

    modint() = default;
    modint(int _val): val(_val){}
    modint operator+(modint b){ return ((this->val + b.val)%MOD); }
    modint operator-(modint b){ return ((MOD + this->val - b.val)%MOD); }
    modint operator*(modint b){ return ((this->val * b.val)%MOD); }
    modint operator^(int a){
        if(a==0)return 1;
        if(a==1)return *this;
        return (((*this)*(*this))^(a>>1))*((*this)^(a&1)); 
    }
};

modint invert(modint a){
    return a^(MOD-2);
}

modint operator/(modint a, modint b){
    return a*invert(b);
}

vector<pii> vec;

int main(){
    detachIO;
    int n;cin>>n;
    int k;cin>>k;
    REP(i,0,n){
        int a,b;cin>>a>>b;
        vec.pb({a,b});
    }
    double ans=2e20;
    REP(i,0,(1<<n)){
        multiset<int> st;
        vector<int> cv;
        REP(j,0,n){
            if(i&(1<<j)){
                cv.pb(vec[j].se);
            } else st.insert(vec[j].fi);
        }
        SORT(cv);
        if(cv.size() && cv[0]==-1)continue;
        double tmp=0;
        int s=cv.size();
        REP(i,0,cv.size()){
            tmp+=cv[i]*1.0/(1+i);
        }
        while(s<k)tmp+=(*st.begin())*1.0/(cv.size()+1),st.erase(st.begin()),s++;
        ans=min(ans,tmp);
    }
    cout<<fixed<<setprecision(20)<<ans<<'\n';
}
#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...