Submission #658799

#TimeUsernameProblemLanguageResultExecution timeMemory
658799GrandTiger1729Let's Win the Election (JOI22_ho_t3)C++17
100 / 100
198 ms2396 KiB
#include <iostream> #include <algorithm> #include <iomanip> #include <queue> using namespace std; const double INF = 1e9; int main(){ cin.tie(0)->sync_with_stdio(0); int n, K; cin >> n >> K; pair<double, double> a[n + 1]{}; for (int i = 1; i <= n; i++){ cin >> a[i].first >> a[i].second; if (a[i].second == -1){ a[i].second = INF; } } sort(a + 1, a + n + 1, [&](pair<double, double> x, pair<double, double> y){ return x.second < y.second; }); double ans = INF; for (int t = 0; t < K; t++){ double dp[n + 1][t + 1]{}; for (int i = 0; i <= n; i++){ fill(dp[i], dp[i] + t + 1, INF); } dp[0][0] = 0; for (int i = 1; i <= n; i++){ for (int j = 1; j <= t; j++){ dp[i][j] = min(dp[i][j], dp[i - 1][j - 1] + a[i].second / j); } for (int j = 0; j <= t; j++){ dp[i][j] = min(dp[i][j], dp[i - 1][j] + a[i].first / (t + 1)); } } double cur = 0; priority_queue<double, vector<double>, greater<double>> pq; for (int i = n; i > K; i--){ pq.push(a[i].first); } double res = INF; for (int i = K; i >= t; i--){ res = min(res, dp[i][t] + cur); pq.push(a[i].first); while (pq.size() > n - K){ cur += pq.top() / (t + 1); pq.pop(); } } ans = min(ans, res); } cout << fixed << setprecision(15) << ans; return 0; }

Compilation message (stderr)

Main.cpp: In function 'int main()':
Main.cpp:45:30: warning: comparison of integer expressions of different signedness: 'std::priority_queue<double, std::vector<double>, std::greater<double> >::size_type' {aka 'long unsigned int'} and 'int' [-Wsign-compare]
   45 |             while (pq.size() > n - K){
      |                    ~~~~~~~~~~^~~~~~~
#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...