Submission #329201

# Submission time Handle Problem Language Result Execution time Memory
329201 2020-11-19T18:00:16 Z Mahdi_Shokoufi Kitchen (BOI19_kitchen) C++17
100 / 100
112 ms 109696 KB
//In The Name of Allah
#include <bits/stdc++.h>

using namespace std;

typedef long long ll;
typedef pair < int , int > pii;
typedef pair < ll , ll > pll;

#define X first
#define Y second
#define mp make_pair
#define pb push_back
#define all(x) (x).begin(), (x).end()
#define sz(x) (int)(x.size())

const int N = 300 + 10;
const int M = 90000 + 10;
const ll mod = 1e9 + 7;
const int inf = 1e9 + 10;

int a[N], b[N], dp[N][M];

int main(){
    ios::sync_with_stdio(0);
    cin.tie(0); cout.tie(0);
    int n, m, k;
    cin >> n >> m >> k;
    int sum = 0, mn = inf;
    for (int i = 1; i <= n; i ++)
        cin >> a[i], sum += a[i], mn = min(mn, a[i]);
    for (int i = 1; i <= m; i ++)
        cin >> b[i];
    if (mn < k)
        return cout << "Impossible", 0;
    for (int i = 0; i < N; i ++)
        for (int j = 0; j < M; j ++)
            dp[i][j] = -inf;
    dp[0][0] = 0;
    for (int i = 1; i <= m; i ++){
        for (int j = 0; j < M; j ++){
            dp[i][j] = dp[i - 1][j];
            if (b[i] <= j && dp[i - 1][j - b[i]] != -inf)
                dp[i][j] = max(dp[i][j], dp[i - 1][j - b[i]] + min(b[i], n));
        }
    }
    int ans = inf;
    for (int j = sum; j < M; j ++)
        if (n * k <= dp[m][j])
            ans = min(ans, j - sum);
    if (ans == inf)
        return cout << "Impossible", 0;
    cout << ans;
    return 0;
}
# Verdict Execution time Memory Grader output
1 Correct 65 ms 109548 KB Output is correct
2 Correct 62 ms 109556 KB Output is correct
3 Correct 63 ms 109548 KB Output is correct
4 Correct 62 ms 109548 KB Output is correct
5 Correct 63 ms 109548 KB Output is correct
6 Correct 1 ms 364 KB Output is correct
7 Correct 1 ms 364 KB Output is correct
8 Correct 62 ms 109548 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 65 ms 109548 KB Output is correct
2 Correct 62 ms 109556 KB Output is correct
3 Correct 63 ms 109548 KB Output is correct
4 Correct 62 ms 109548 KB Output is correct
5 Correct 63 ms 109548 KB Output is correct
6 Correct 1 ms 364 KB Output is correct
7 Correct 1 ms 364 KB Output is correct
8 Correct 62 ms 109548 KB Output is correct
9 Correct 68 ms 109548 KB Output is correct
10 Correct 75 ms 109608 KB Output is correct
11 Correct 64 ms 109548 KB Output is correct
12 Correct 68 ms 109568 KB Output is correct
13 Correct 74 ms 109544 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 98 ms 109548 KB Output is correct
2 Correct 104 ms 109676 KB Output is correct
3 Correct 107 ms 109548 KB Output is correct
4 Correct 110 ms 109548 KB Output is correct
5 Correct 104 ms 109548 KB Output is correct
6 Correct 91 ms 109548 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 72 ms 109548 KB Output is correct
2 Correct 68 ms 109548 KB Output is correct
3 Correct 68 ms 109548 KB Output is correct
4 Correct 68 ms 109568 KB Output is correct
5 Correct 1 ms 384 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 65 ms 109548 KB Output is correct
2 Correct 62 ms 109556 KB Output is correct
3 Correct 63 ms 109548 KB Output is correct
4 Correct 62 ms 109548 KB Output is correct
5 Correct 63 ms 109548 KB Output is correct
6 Correct 1 ms 364 KB Output is correct
7 Correct 1 ms 364 KB Output is correct
8 Correct 62 ms 109548 KB Output is correct
9 Correct 68 ms 109548 KB Output is correct
10 Correct 75 ms 109608 KB Output is correct
11 Correct 64 ms 109548 KB Output is correct
12 Correct 68 ms 109568 KB Output is correct
13 Correct 74 ms 109544 KB Output is correct
14 Correct 98 ms 109548 KB Output is correct
15 Correct 104 ms 109676 KB Output is correct
16 Correct 107 ms 109548 KB Output is correct
17 Correct 110 ms 109548 KB Output is correct
18 Correct 104 ms 109548 KB Output is correct
19 Correct 91 ms 109548 KB Output is correct
20 Correct 72 ms 109548 KB Output is correct
21 Correct 68 ms 109548 KB Output is correct
22 Correct 68 ms 109548 KB Output is correct
23 Correct 68 ms 109568 KB Output is correct
24 Correct 1 ms 384 KB Output is correct
25 Correct 91 ms 109560 KB Output is correct
26 Correct 105 ms 109548 KB Output is correct
27 Correct 84 ms 109548 KB Output is correct
28 Correct 100 ms 109696 KB Output is correct
29 Correct 98 ms 109548 KB Output is correct
30 Correct 112 ms 109548 KB Output is correct