fork(1) download
  1. #include <bits/stdc++.h>
  2. using namespace std;
  3.  
  4. int T, N; double P, H[1009], W[1009], dp[109][25252];
  5.  
  6. long double solve() {
  7. for (int i = 0; i <= N; i++) {
  8. for (int j = 0; j <= N * 250; j++) dp[i][j] = -1e9;
  9. }
  10. dp[0][0] = 0.0L;
  11. for (int i = 0; i < N; i++) {
  12. for (int j = 0; j <= N * 250; j++) {
  13. if (dp[i][j] <= -1e8) continue;
  14.  
  15. dp[i + 1][j] = max(dp[i + 1][j], dp[i][j]);
  16. int U = j + min(H[i], W[i]);
  17. dp[i + 1][U] = max(1.0L*dp[i + 1][U], 1.0L*dp[i][j] + sqrtl(H[i] * H[i] + W[i] * W[i]));
  18. }
  19. }
  20. long double sum1 = 0.0L;
  21. for (int i = 0; i < N; i++) { P -= 2.0L*(H[i] + W[i]); sum1 += 2.0L*(H[i] + W[i]); }
  22. P /= 2;
  23. long double ret = 0.0L;
  24. for (int j = 0; j <= N * 250; j++) {
  25. if (dp[N][j] <= -1e8 || 1.0L*j >= P + 1e-7) continue;
  26. ret = max(ret, 1.0L*min(P, dp[N][j]));
  27. }
  28. return ret*2.0L + sum1;
  29. }
  30.  
  31. int main() {
  32. cin >> T;
  33. for (int i = 0; i < T; i++) {
  34. cin >> N >> P;
  35. for (int j = 0; j < N; j++) cin >> H[j] >> W[j];
  36.  
  37. printf("Case #%d: %.12Lf\n", i + 1, solve());
  38. }
  39. return 0;
  40. }
Success #stdin #stdout 0s 4412KB
stdin
4
1 7
1 1
2 920
50 120
50 120
1 32
7 4
3 240
10 20
20 30
30 10
stdout
Case #1: 6.828427124746
Case #2: 920.000000000000
Case #3: 32.000000000000
Case #4: 240.000000000000