답안 #771753

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
771753 2023-07-03T08:52:23 Z teo_thrash Kitchen (BOI19_kitchen) C++14
0 / 100
96 ms 262144 KB
#include<bits/stdc++.h>
#define pb push_back

using namespace std;

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

const int maxn=1e6+3;
const int mod=1e9+7;

int n, m, k, a[maxn], b[maxn];
int dp[320][maxn];
int min_a=INT_MAX;
int a_sum=0, b_sum=0;

int main(){

ios_base::sync_with_stdio(false);
cin.tie(NULL);
cout.tie(NULL);

cin>>n>>m>>k;
for(int i=1; i<=n; i++){
    cin>>a[i];

    if(a[i]<k){
        cout<<"Impossible";
        return 0;
    }

    a_sum+=a[i];
}
for(int i=1; i<=m; i++){
    cin>>b[i];
    b_sum+=b[i];
}

memset(dp, -1, sizeof(dp));

dp[0][0]=0;

for(int i=1; i<=m; i++){

    for(int j=1; j<=b_sum; j++){
        dp[i][j]=dp[i-1][j];

        if(b[i]<=j){
            dp[i][j]=max(dp[i][j], dp[i-1][j-b[i]]+min(n, b[i]));
        }
    }
}

int ans=INT_MAX;
for(int j=a_sum; j<=b_sum; j++){
    if(dp[m][j]>=n*k){
        cout<<j-a_sum<<endl;
        return 0;
    }
}

cout<<"Impossible";

return 0;
}

Compilation message

kitchen.cpp: In function 'int main()':
kitchen.cpp:54:5: warning: unused variable 'ans' [-Wunused-variable]
   54 | int ans=INT_MAX;
      |     ^~~
# 결과 실행 시간 메모리 Grader output
1 Runtime error 96 ms 262144 KB Execution killed with signal 9
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Runtime error 96 ms 262144 KB Execution killed with signal 9
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Runtime error 88 ms 262144 KB Execution killed with signal 9
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Runtime error 79 ms 262144 KB Execution killed with signal 9
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Runtime error 96 ms 262144 KB Execution killed with signal 9
2 Halted 0 ms 0 KB -