답안 #552012

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
552012 2022-04-22T07:55:17 Z ollel Kitchen (BOI19_kitchen) C++14
100 / 100
69 ms 1536 KB
using namespace std;
#include <bits/stdc++.h>

#define rep(i,a,b) for(int i = a; i < b; i++)
typedef vector<int> vi;
typedef vector<vi> vvi;

int n, m, k;
vi a, b;

int main() {
  cin >> n >> m >> k;
  a.resize(n);
  b.resize(m);
  rep(i,0,n) cin >> a[i];
  rep(i,0,m) cin >> b[i];

  rep(i,0,n) if (a[i] < k) {
    cout << "Impossible\n";
    exit(0);
  }


  // dp[i] = num
  // dp[i] = maximum sum2 with sum1 = i?

  const int maxs = 330*330;
  vvi dp(2, vi(maxs, -1));
  dp[0][0] = 0; dp[1][0] = 0;
  rep(i,0,m) {
    int sum1 = b[i];
    int sum2 = min(b[i], n);
    int i1 = i&1;
    rep(j,0,maxs - sum1) {
      if (dp[i1][j] == -1) continue;
      dp[i1^1][j + sum1] = max(dp[i1^1][j + sum1], dp[i1][j] + sum2);
      dp[i1^1][j] = max(dp[i1^1][j], dp[i1][j]);
    }
  }
  int minimi = n * k;
  int start = 0;
  rep(i,0,n) start += a[i];
  rep(i, start, maxs) {
    if (dp[0][i] >= minimi || dp[1][i] >= minimi) {
      cout << (i - start) << endl;
      exit(0);
    }
  }
  cout << "Impossible" << endl;
}
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 1492 KB Output is correct
2 Correct 1 ms 1492 KB Output is correct
3 Correct 1 ms 1492 KB Output is correct
4 Correct 1 ms 1536 KB Output is correct
5 Correct 1 ms 1492 KB Output is correct
6 Correct 0 ms 212 KB Output is correct
7 Correct 1 ms 212 KB Output is correct
8 Correct 1 ms 1492 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 1492 KB Output is correct
2 Correct 1 ms 1492 KB Output is correct
3 Correct 1 ms 1492 KB Output is correct
4 Correct 1 ms 1536 KB Output is correct
5 Correct 1 ms 1492 KB Output is correct
6 Correct 0 ms 212 KB Output is correct
7 Correct 1 ms 212 KB Output is correct
8 Correct 1 ms 1492 KB Output is correct
9 Correct 2 ms 1492 KB Output is correct
10 Correct 2 ms 1492 KB Output is correct
11 Correct 2 ms 1492 KB Output is correct
12 Correct 2 ms 1492 KB Output is correct
13 Correct 3 ms 1492 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 29 ms 1492 KB Output is correct
2 Correct 27 ms 1492 KB Output is correct
3 Correct 48 ms 1492 KB Output is correct
4 Correct 69 ms 1492 KB Output is correct
5 Correct 60 ms 1492 KB Output is correct
6 Correct 22 ms 1492 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 4 ms 1492 KB Output is correct
2 Correct 4 ms 1492 KB Output is correct
3 Correct 4 ms 1492 KB Output is correct
4 Correct 4 ms 1492 KB Output is correct
5 Correct 1 ms 212 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 1492 KB Output is correct
2 Correct 1 ms 1492 KB Output is correct
3 Correct 1 ms 1492 KB Output is correct
4 Correct 1 ms 1536 KB Output is correct
5 Correct 1 ms 1492 KB Output is correct
6 Correct 0 ms 212 KB Output is correct
7 Correct 1 ms 212 KB Output is correct
8 Correct 1 ms 1492 KB Output is correct
9 Correct 2 ms 1492 KB Output is correct
10 Correct 2 ms 1492 KB Output is correct
11 Correct 2 ms 1492 KB Output is correct
12 Correct 2 ms 1492 KB Output is correct
13 Correct 3 ms 1492 KB Output is correct
14 Correct 29 ms 1492 KB Output is correct
15 Correct 27 ms 1492 KB Output is correct
16 Correct 48 ms 1492 KB Output is correct
17 Correct 69 ms 1492 KB Output is correct
18 Correct 60 ms 1492 KB Output is correct
19 Correct 22 ms 1492 KB Output is correct
20 Correct 4 ms 1492 KB Output is correct
21 Correct 4 ms 1492 KB Output is correct
22 Correct 4 ms 1492 KB Output is correct
23 Correct 4 ms 1492 KB Output is correct
24 Correct 1 ms 212 KB Output is correct
25 Correct 21 ms 1492 KB Output is correct
26 Correct 33 ms 1492 KB Output is correct
27 Correct 25 ms 1492 KB Output is correct
28 Correct 38 ms 1492 KB Output is correct
29 Correct 43 ms 1492 KB Output is correct
30 Correct 58 ms 1492 KB Output is correct