# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
1072080 | _rain_ | Let's Win the Election (JOI22_ho_t3) | C++14 | 6 ms | 4412 KiB |
This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define fixbug false
#define double long double
void SETIO(string name = ""){
if (name=="") return;
freopen((name+".inp").c_str(),"r",stdin);
// freopen((name+".out").c_str(),"w",stdout);
return;
}
const int maxn = 500;
const int maxk = 500;
const int INF = 1e9 + 7;
int n , k ;
pair<int,int> a[maxn+2];
#define fi first
#define se second
bool cmp(pair<int,int> a , pair<int,int> b){
if (a.second != b.second) return a.second < b.second;
return a.first < b.first;
}
double dp[maxn+2][maxk+2] , f[maxn+2];
int main(){
ios::sync_with_stdio(0);
cin.tie(0); cout.tie(0);
SETIO("");
cin >> n >> k;
for (int i = 0; i <= n + 1; ++i){
for (int j = 0; j <= k + 1; ++j) dp[i][j] = INF;
}
for (int i = 1; i <= n; ++i) {
cin >> a[i].fi >> a[i].se;
if (a[i].se==-1) a[i].se = INF;
}
sort(a+1,a+n+1,cmp);
cout << setprecision(10) << fixed ;
if (fixbug){
cout << "(DEBUG)\n";
for (int i = 1; i <= n; ++i) cout << a[i].fi << ' ' << a[i].se << '\n';
}
for (int i = 0; i <= n + 1; ++i) dp[i][0] = 0;
for (int i = n; i >= 1; --i){
dp[i][1] = a[i].first;
for (int num = 1; num <= k; ++num){
dp[i][num] = min(dp[i + 1][num] , dp[i][num]);
dp[i][num] = min(dp[i][num] , dp[i + 1][num - 1] + a[i].first);
}
}
f[0] = 0 ;
double ans = dp[1][k];
for (int i = 1; i <= k; ++i){
f[i] = f[i - 1] + a[i].second / (double)i;
if (k - i == 0 || a[i].second == INF) continue;
ans = min(ans , f[i] + dp[i + 1][k - i] / (double)(i + 1));
}
if (fixbug){
cout << "( FIX BUG )\n";
for (int i = 1; i <= k; ++i) {
cout << "(( OOO-OOO )) " << dp[i + 1][k - i] << '\n';
cout << f[i] << ' ' << dp[i + 1][k - i] / (double)(i + 1) << "\n";
}
}
cout << ans;
}
Compilation message (stderr)
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |