Submission #1208436

#TimeUsernameProblemLanguageResultExecution timeMemory
1208436dima2101Let's Win the Election (JOI22_ho_t3)C++20
100 / 100
659 ms4388 KiB
#include <bits/stdc++.h>
#define int long long

const int MAXN = 502;
long double dp[MAXN][MAXN];

signed
main()
{
    std::ios::sync_with_stdio(false);
    std::cin.tie(0);

    int n, k;
    std::cin >> n >> k;

    std::vector<std::pair<int, int>> all(n);
    for (int i = 0; i < n; i++)
    {
        std::cin >> all[i].first >> all[i].second;
        if (all[i].second == -1)
        {
            all[i].second = 1e13;
        }
    }
    std::sort(all.begin(), all.end(), [&](std::pair<int, int> a, std::pair<int, int> b)
              { return a.second < b.second; });
    long double min = 1e18;
    for (int i = 0; i <= k; i++)
    {
        for (int j = 0; j <= n; j++)
        {
            for (int z = 0; z <= n; z++)
            {
                dp[j][z] = 1e9;
            }
        }
        dp[0][0] = 0;
        for (int j = 1; j <= n; j++)
        {
            for (int z = 0; z <= std::min(k - i, j); z++)
            {
                int first = std::min((j - z), i);
                if (z > 0)
                {
                    dp[j][z] = std::min(dp[j][z], dp[j - 1][z - 1] + (long double)(all[j - 1].first) / (long double)(i + 1));
                }
                if ((j - 1 - z) < i)
                {
                    dp[j][z] = std::min(dp[j][z], dp[j - 1][z] + (long double)(all[j - 1].second) / (long double)(first));
                }
                else
                {
                    dp[j][z] = std::min(dp[j][z], dp[j - 1][z]);
                }
                // std::cout << dp[j][z] << ' ' << j << ' ' << z << ' ' << std::min(k - i, j) << std::endl;
            }
        }
        // std::cout << dp[n][k - i] << std::endl;

        min = std::min(min, dp[n][k - i]);
    }
    std::cout << std::setprecision(10) << std::fixed << min;
}
#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...