답안 #925792

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
925792 2024-02-12T08:54:50 Z vjudge1 Kitchen (BOI19_kitchen) C++17
9 / 100
77 ms 234312 KB
// #pragma GCC target ("avx2")
// #pragma GCC optimization ("O3")
// #pragma GCC optimization ("unroll-loops")

#include <bits/stdc++.h>

#define int long long
#define ff first
#define ss second
#define pb push_back
#define yes cout<<"Yes\n"
#define no cout<<"No\n"
#define no1 cout<<"-1\n"

using namespace std;

const int N = 301;
const int M = 1e5+10;
const int INF = 1e18;
const int mod = 998244353;
  
// int binpow (int a, int n) {
// 	if (n == 0)
// 		return 1;
// 	if (n % 2 == 1)
// 		return (binpow (a, n-1) * a)%mod;
// 	else {
// 		int b = binpow (a, n/2) % mod;
// 		return (b * b)%mod;
// 	}
// }

int n,m,k;
int a[N];
int b[N];
int dp[N][M];
int sum1;
int sum2;

void solve(){
    cin>>n>>m>>k;
    for(int i = 1;i<=n;i++){
        cin>>a[i];
        sum1+=a[i];
    }
    for(int i = 1;i<=m;i++){
        cin>>b[i];
        sum2+=b[i];
    }
    
    if(sum2<sum1){
        cout<<"Impossible\n";
        return;
    }

    //sub1

    if(m>2){
        for(int i = 0;i<=n;i++){
            dp[i][0] = 1;
        }
        for(int i = 1;i<=n;i++){
            for(int j = b[i];j<=sum2;j++){
                dp[i][j] = dp[i-1][j-b[i]];
            }
        }
        int mn = INF;
        for(int i = 0;i<=n;i++){
            for(int j = sum1;j<=sum2;j++){
                if(dp[i][j]){
                    mn = min(mn,j);
                }
            }
        }
        cout<<mn-sum1<<'\n';
        return;
    }

    //sub2

    if(k>2){
        cout<<"Impossible\n";
        return;
    }
    if(k==2){
        if(m==1){
            cout<<"Impossible\n";
            return;
        }
        int sum = 0;
        for(int i = 1;i<=n;i++){
            if(a[i] == 1){
                cout<<"Impossible\n";
                return;
            }
            sum+=a[i];
        }
        if(b[1]+b[2] < sum){
            cout<<"Impossible\n";
            return;
        }
        cout<<b[1]+b[2]-sum;
    }
    if(k==1){
        int sum = 0;
        for(int i = 1;i<=n;i++){
            sum+=a[i];
        }
        if(b[1]+b[2] < sum){
            cout<<"Impossible\n";
            return;
        }
        int x,y,z;
        x = y = z = INF;
        z = b[1]+b[2]-sum;
        if(b[1]>=sum) x = b[1]-sum;
        if(b[2]>=sum) y = b[2]-sum;
        cout<<min({x,y,z});
    }
}

signed main(){
    ios_base::sync_with_stdio(0);
    cin.tie(nullptr);
    // cout.tie(nullptr);
    int t = 1; 
    // cin>>t;
    //   cout<<"";
    for(int i = 1;i<=t;i++){
        solve();
        // cout<<'\n';
    }
}
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 344 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 0 ms 348 KB Output is correct
5 Correct 0 ms 348 KB Output is correct
6 Correct 0 ms 348 KB Output is correct
7 Correct 0 ms 360 KB Output is correct
8 Correct 0 ms 360 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 344 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 0 ms 348 KB Output is correct
5 Correct 0 ms 348 KB Output is correct
6 Correct 0 ms 348 KB Output is correct
7 Correct 0 ms 360 KB Output is correct
8 Correct 0 ms 360 KB Output is correct
9 Incorrect 1 ms 6492 KB Output isn't correct
10 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 77 ms 234312 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 3 ms 20824 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 344 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 0 ms 348 KB Output is correct
5 Correct 0 ms 348 KB Output is correct
6 Correct 0 ms 348 KB Output is correct
7 Correct 0 ms 360 KB Output is correct
8 Correct 0 ms 360 KB Output is correct
9 Incorrect 1 ms 6492 KB Output isn't correct
10 Halted 0 ms 0 KB -