Submission #794852

#TimeUsernameProblemLanguageResultExecution timeMemory
794852gun_ganLet's Win the Election (JOI22_ho_t3)C++17
100 / 100
163 ms2380 KiB
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
 
const int MX = 505;
 
int N, K;
int a[MX], b[MX];
double dp[MX][MX];
 
vector<pair<int, int>> v;
 
int main() {
      cin.tie(0); ios_base::sync_with_stdio(0);
 
      cin >> N >> K;
 
      int tot = 0;
      for(int i = 1; i <= N; i++) {
            cin >> a[i] >> b[i];
            if(b[i] != -1) tot++;
            else b[i] = 1e9;
            v.push_back({b[i], a[i]});
      }
 
      sort(v.begin(), v.end());
 
      double ans = 1e9;
      for(int x = 0; x <= min(K, tot); x++) { // fixed collaborator
            for(int i = 0; i < MX; i++)
                  for(int j = 0; j < MX; j++)
                        dp[i][j] = 1e9;
       
            dp[0][0] = 0;
            for(int i = 0; i < N; i++) {
                  for(int j = 0; j <= K - x; j++) { // votes
                        if(dp[i][j] == 1e9) continue;

                        // ambil vote doang
                        dp[i + 1][j + 1] = min(dp[i + 1][j + 1], dp[i][j] + (double) v[i].second / (x + 1));
                        
                        // ambil collaborator / skip
                        if(i - j < x)
                              dp[i + 1][j] = min(dp[i + 1][j], dp[i][j] + (double) v[i].first / (i - j + 1));
                        else
                              dp[i + 1][j] = min(dp[i + 1][j], dp[i][j]); 
                  }
            }
 
            ans = min(ans, dp[N][K - x]);
      }
 
      cout << fixed << setprecision(15) << 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...