제출 #1005501

#제출 시각아이디문제언어결과실행 시간메모리
1005501anangoKitchen (BOI19_kitchen)C++17
0 / 100
213 ms262144 KiB
#include <bits/stdc++.h>
using namespace std;
#define int long long

signed main() {
    freopen("input.txt","r", stdin);
    freopen("output.txt","w",stdout);
    int n,m,k;
    cin >> n >> m >> k;
    int fail=0;
    vector<int> a,b;
    for (int i=0; i<n; i++) {
        int x;
        cin >> x;
        if (x<k) {
            fail=1;
        }

        a.push_back(x);

    }
    for (int i=0; i<m; i++) {
        int x;
        cin >> x;
        b.push_back(x);
    }
    if (fail) {
        cout << "Impossible" << endl;
        return 0;
    }
    sort(b.begin(), b.end());
    int S = accumulate(b.begin(), b.end(), (int)0)+1;
    int T = accumulate(a.begin(), a.end(), (int)0);
    int dp[S];
    for (int j=0; j<=S; j++) {
        dp[j] = -1;
    }
    dp[0] = 0;
    for (int i=0; i<m; i++) {
        int val = b[i]; 
        for (int j=S; j>=val; j--) {
            if (dp[j-val]!=-1) {
                dp[j] = max(dp[j],dp[j-val]+min(n,val));
            }
        }
    }
    int ans = -1;
    for (int i=T; i<=S; i++) {
        //cout << i <<" " << dp[i] << endl;
        if (dp[i]>=n*k) {
            ans=i-T;
            break;
        }
    }
    if (ans==-1) {
        cout << "Impossible" << endl;
    }
    else {
        cout << ans << endl;
    }
}

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

kitchen.cpp: In function 'int main()':
kitchen.cpp:6:12: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
    6 |     freopen("input.txt","r", stdin);
      |     ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~
kitchen.cpp:7:12: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
    7 |     freopen("output.txt","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...