Submission #747929

#TimeUsernameProblemLanguageResultExecution timeMemory
747929MilosMilutinovicLet's Win the Election (JOI22_ho_t3)C++14
10 / 100
291 ms4300 KiB
#include <bits/stdc++.h> using namespace std; const int N = 505; int n, k, a[N], b[N], ord[N]; double dp[N][N], ndp[N][N]; bool cmp(int i, int j) { int si = a[i] + (b[i] == -1 ? 1e8 : b[i]); int sj = a[j] + (b[j] == -1 ? 1e8 : b[j]); if (si != sj) return si < sj; else return a[i] < a[j]; } int main() { scanf("%d%d", &n, &k); for (int i = 1; i <= n; i++) scanf("%d%d", &a[i], &b[i]), b[i] = (b[i] == -1 ? -1 : b[i] - a[i]); for (int i = 1; i <= n; i++) ord[i] = i; sort(ord + 1, ord + n + 1, cmp); for (int i = 0; i <= n + 1; i++) for (int j = 0; j <= n + 1; j++) dp[i][j] = 1e9; dp[0][1] = 0; for (int _i = 1; _i <= n; _i++) { int i = ord[_i]; for (int j = 0; j <= n + 1; j++) for (int l = 0; l <= n + 1; l++) ndp[j][l] = dp[j][l]; for (int j = 0; j <= n + 1; j++) { for (int l = 0; l <= n + 1; l++) { if (ndp[j][l] > 1e8) continue; dp[j + 1][l] = min(dp[j + 1][l], ndp[j][l] + (double) (a[i] + 0.0) / l); if (b[i] != -1) dp[j + 1][l + 1] = min(dp[j + 1][l + 1], ndp[j][l] + (double) (a[i] + b[i] + 0.0) / l); } } } double ans = 1e9; for (int i = 0; i <= n + 1; i++) ans = min(ans, dp[k][i]); printf("%.20lf", ans); return 0; }

Compilation message (stderr)

Main.cpp: In function 'int main()':
Main.cpp:13:10: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   13 |     scanf("%d%d", &n, &k);
      |     ~~~~~^~~~~~~~~~~~~~~~
Main.cpp:14:39: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   14 |     for (int i = 1; i <= n; i++) scanf("%d%d", &a[i], &b[i]), b[i] = (b[i] == -1 ? -1 : b[i] - a[i]);
      |                                  ~~~~~^~~~~~~~~~~~~~~~~~~~~~
#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...