제출 #1124386

#제출 시각아이디문제언어결과실행 시간메모리
1124386whoknowKitchen (BOI19_kitchen)C++20
100 / 100
15 ms584 KiB
#include <bits/stdc++.h>
#define ll long long
#define F first
#define S second
#define MAXN 305
#define MAXSUM 90005
#define ii pair<int,int>
#define bit(i,j) ((i>>j)&1)
#define sz(i) (int)i.size()
#define endl '\n'
using namespace std;
int n, m, K;
int a[MAXN], b[MAXN];
namespace sub1
{
int sumA, sumB;
int dp[MAXSUM];
void solve()
{
    for(int i = 1; i <= n; i++)
    {
        if(a[i] < K)
            return cout << "Impossible", void();
        sumA += a[i];
    }
    for(int i = 1; i <= m; i++)
        sumB += b[i];
    memset(dp, -0x3f, sizeof(dp));
    dp[0] = 0;
    for(int i = 1; i <= m; i++)
        for(int j = sumB; j >= b[i]; j--)
            dp[j] = max(dp[j], dp[j - b[i]] + min(b[i], n));
    for(int i = sumA; i <= sumB; i++)
        if(dp[i] >= n * K)
            return cout << i - sumA, void();
    cout << "Impossible";
}
}
main()
{
    if(fopen("TEST.inp", "r"))
    {
        freopen("TEST.inp", "r", stdin);
        freopen("TEST.out", "w", stdout);
    }
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    cin >> n >> m >> K;
    for(int i = 1; i <= n; i++)
        cin >> a[i];
    for(int i = 1; i <= m; i++)
        cin >> b[i];
    if(K > m)
        return cout << "Impossible", 0;
    sub1::solve();
}
/**
2 4 3
5 5
1 4 5 1

**/

컴파일 시 표준 에러 (stderr) 메시지

kitchen.cpp:39:1: warning: ISO C++ forbids declaration of 'main' with no type [-Wreturn-type]
   39 | main()
      | ^~~~
kitchen.cpp: In function 'int main()':
kitchen.cpp:43:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   43 |         freopen("TEST.inp", "r", stdin);
      |         ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~
kitchen.cpp:44:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   44 |         freopen("TEST.out", "w", stdout);
      |         ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~
#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...