답안 #909620

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
909620 2024-01-17T09:54:45 Z MilosMilutinovic 스트랩 (JOI14_straps) C++14
100 / 100
22 ms 764 KB
#include <bits/stdc++.h>

using namespace std;

int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  int n;
  cin >> n;
  vector<int> a(n), b(n);
  for (int i = 0; i < n; i++) {
    cin >> a[i] >> b[i];
  }
  const long long inf = (long long) 1e18;
  vector<long long> dp(2 * n + 1, -inf);
  dp[n + 1] = 0;
  for (int i = 0; i < n; i++) {
    auto new_dp = dp;
    for (int bal = -n; bal <= n; bal++) {
      int new_bal = min(n, bal - 1 + a[i]);
      if (new_bal >= -n) {
        new_dp[new_bal + n] = max(new_dp[new_bal + n], dp[bal + n] + b[i]);
      }
    }
    swap(dp, new_dp);
  }
  long long res = 0;
  for (int i = 0; i <= n; i++) {
    res = max(res, dp[n + i]);
  }
  cout << res << '\n';
  return 0;
}
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 344 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 0 ms 452 KB Output is correct
4 Correct 0 ms 348 KB Output is correct
5 Correct 1 ms 348 KB Output is correct
6 Correct 0 ms 348 KB Output is correct
7 Correct 0 ms 348 KB Output is correct
8 Correct 1 ms 344 KB Output is correct
9 Correct 1 ms 348 KB Output is correct
10 Correct 0 ms 348 KB Output is correct
11 Correct 1 ms 348 KB Output is correct
12 Correct 1 ms 348 KB Output is correct
13 Correct 1 ms 348 KB Output is correct
14 Correct 1 ms 344 KB Output is correct
15 Correct 1 ms 348 KB Output is correct
16 Correct 0 ms 348 KB Output is correct
17 Correct 1 ms 344 KB Output is correct
18 Correct 1 ms 344 KB Output is correct
19 Correct 0 ms 348 KB Output is correct
20 Correct 1 ms 348 KB Output is correct
21 Correct 1 ms 452 KB Output is correct
22 Correct 1 ms 348 KB Output is correct
23 Correct 0 ms 348 KB Output is correct
24 Correct 1 ms 348 KB Output is correct
25 Correct 1 ms 604 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 608 KB Output is correct
2 Correct 1 ms 348 KB Output is correct
3 Correct 1 ms 348 KB Output is correct
4 Correct 1 ms 348 KB Output is correct
5 Correct 1 ms 344 KB Output is correct
6 Correct 1 ms 348 KB Output is correct
7 Correct 1 ms 348 KB Output is correct
8 Correct 4 ms 504 KB Output is correct
9 Correct 6 ms 500 KB Output is correct
10 Correct 5 ms 348 KB Output is correct
11 Correct 4 ms 348 KB Output is correct
12 Correct 16 ms 344 KB Output is correct
13 Correct 16 ms 348 KB Output is correct
14 Correct 15 ms 348 KB Output is correct
15 Correct 16 ms 348 KB Output is correct
16 Correct 16 ms 560 KB Output is correct
17 Correct 16 ms 348 KB Output is correct
18 Correct 22 ms 348 KB Output is correct
19 Correct 15 ms 348 KB Output is correct
20 Correct 20 ms 344 KB Output is correct
21 Correct 16 ms 348 KB Output is correct
22 Correct 16 ms 344 KB Output is correct
23 Correct 16 ms 348 KB Output is correct
24 Correct 15 ms 348 KB Output is correct
25 Correct 17 ms 344 KB Output is correct
26 Correct 18 ms 348 KB Output is correct
27 Correct 18 ms 348 KB Output is correct
28 Correct 15 ms 552 KB Output is correct
29 Correct 18 ms 564 KB Output is correct
30 Correct 20 ms 348 KB Output is correct
31 Correct 21 ms 344 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 348 KB Output is correct
2 Correct 1 ms 348 KB Output is correct
3 Correct 1 ms 348 KB Output is correct
4 Correct 1 ms 456 KB Output is correct
5 Correct 1 ms 348 KB Output is correct
6 Correct 1 ms 348 KB Output is correct
7 Correct 1 ms 348 KB Output is correct
8 Correct 1 ms 348 KB Output is correct
9 Correct 4 ms 344 KB Output is correct
10 Correct 6 ms 504 KB Output is correct
11 Correct 4 ms 508 KB Output is correct
12 Correct 4 ms 344 KB Output is correct
13 Correct 4 ms 472 KB Output is correct
14 Correct 5 ms 348 KB Output is correct
15 Correct 5 ms 348 KB Output is correct
16 Correct 4 ms 348 KB Output is correct
17 Correct 16 ms 488 KB Output is correct
18 Correct 16 ms 348 KB Output is correct
19 Correct 16 ms 564 KB Output is correct
20 Correct 17 ms 352 KB Output is correct
21 Correct 17 ms 564 KB Output is correct
22 Correct 17 ms 564 KB Output is correct
23 Correct 19 ms 344 KB Output is correct
24 Correct 20 ms 764 KB Output is correct
25 Correct 16 ms 356 KB Output is correct
26 Correct 18 ms 352 KB Output is correct
27 Correct 17 ms 532 KB Output is correct
28 Correct 17 ms 552 KB Output is correct
29 Correct 17 ms 568 KB Output is correct
30 Correct 17 ms 556 KB Output is correct
31 Correct 17 ms 348 KB Output is correct
32 Correct 16 ms 548 KB Output is correct
33 Correct 20 ms 348 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 16 ms 356 KB Output is correct
2 Correct 17 ms 360 KB Output is correct
3 Correct 16 ms 552 KB Output is correct
4 Correct 17 ms 348 KB Output is correct
5 Correct 16 ms 348 KB Output is correct
6 Correct 16 ms 348 KB Output is correct
7 Correct 16 ms 444 KB Output is correct
8 Correct 18 ms 348 KB Output is correct
9 Correct 17 ms 344 KB Output is correct
10 Correct 16 ms 556 KB Output is correct
11 Correct 16 ms 556 KB Output is correct
12 Correct 17 ms 348 KB Output is correct
13 Correct 15 ms 344 KB Output is correct
14 Correct 16 ms 348 KB Output is correct
15 Correct 16 ms 348 KB Output is correct
16 Correct 16 ms 348 KB Output is correct
17 Correct 16 ms 552 KB Output is correct
18 Correct 17 ms 348 KB Output is correct
19 Correct 19 ms 568 KB Output is correct
20 Correct 21 ms 560 KB Output is correct
21 Correct 19 ms 348 KB Output is correct
22 Correct 20 ms 496 KB Output is correct
23 Correct 21 ms 348 KB Output is correct
24 Correct 21 ms 348 KB Output is correct
25 Correct 19 ms 348 KB Output is correct