#include<bits/stdc++.h>
using namespace std;
#define int long long
#define endl "\n"
const int INF = 1e18;
mt19937 rng((unsigned int) chrono::steady_clock::now().time_since_epoch().count());
bool cmp(pair<int,int> a, pair<int,int> b){
if(a.second == b.second) return a.first < b.first;
return a.second-a.first < b.second-b.first;
}
void shuffle(vector<pair<int,int>>& v){
int n = v.size();
for(int i = 0; i<3*n; i++){
int a = rng()%n; int b = rng()%n;
swap(v[a],v[b]);
}
}
signed main(){
ios_base::sync_with_stdio(0);
cin.tie(0);
cout<<setprecision(3)<<fixed;
int n,k1; cin>>n>>k1;
vector<pair<int,int>> v(n);
for(int i = 0; i<n; i++){
cin>>v[i].first>>v[i].second;
if(v[i].second == -1) v[i].second = INF;
}
sort(v.begin(),v.end(),cmp);
long double ans = INF;
// do{
// shuffle(v);
long double dp[n+1][k1+1][k1+1];
for(int i = 0; i<=n; i++){
for(int j = 0; j<=k1; j++){
for(int k = 0; k<=k1; k++) dp[i][j][k] = 1.0*INF;
}
}
dp[0][0][0] = 0; // first i, j votes, k representants
for(int i = 1; i<=n; i++){
for(int j = 0; j<=k1; j++){
for(int k = 0; k<=k; k++){
dp[i][j][k] = dp[i-1][j][k];
if(!j) continue;
long double act = dp[i-1][j-1][k]; // just speech for vote
act+= 1.0*v[i-1].first/(k+1);
dp[i][j][k] = min(dp[i][j][k],act);
if(!k || v[i-1].second == INF) continue;
act = dp[i-1][j-1][k-1];
act+= 1.0*v[i-1].second / k;
dp[i][j][k] = min(dp[i][j][k],act);
}
}
}
for(int k = 0; k<=k1; k++){
ans = min(ans, dp[n][k1][k]);
}
// }while(next_permutation(v.begin(),v.end()));
cout<<ans<<endl;
}
Compilation message
Main.cpp: In function 'int main()':
Main.cpp:45:21: warning: self-comparison always evaluates to true [-Wtautological-compare]
45 | for(int k = 0; k<=k; k++){
| ~^~~
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Execution timed out |
2529 ms |
344 KB |
Time limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Execution timed out |
2529 ms |
344 KB |
Time limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Execution timed out |
2536 ms |
348 KB |
Time limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Execution timed out |
2536 ms |
348 KB |
Time limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Execution timed out |
2536 ms |
348 KB |
Time limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Runtime error |
503 ms |
1048576 KB |
Execution killed with signal 9 |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Execution timed out |
2529 ms |
344 KB |
Time limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |