Submission #925604

# Submission time Handle Problem Language Result Execution time Memory
925604 2024-02-12T06:11:59 Z vjudge1 Kitchen (BOI19_kitchen) C++17
0 / 100
44 ms 7256 KB
// By ObeliX
#include <bits/stdc++.h>
#pragma GCC target( "sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
#pragma GCC optimize("Ofast,no-stack-protector,unroll-loops,fast-math,O3")
#include <unordered_map>
#include <cstddef>
#include <cassert>
#include <bitset>
#include <algorithm>
#include <iostream>
#include <iomanip>
#include <cmath>
#include <queue>
#include <map>
#include <set>

using namespace std;

const long long N = 1e6 + 5;
const long long MOD = 1e7 + 7;
const long long inf = 1e18;

long long n , m , k;
long long a[N] , b[N];
long long dp[3][N];

int main(){
    //freopen( "cinema.in" , "r" , stdin );
    //freopen( "cinema.out" , "w" , stdout );
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    cout.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 == 1 ) {
        sort( b + 1 , b + 1 + n );
        long long sum = 0;
        for ( int i = 1 ; i <= n ; i++ ) {
            sum += a[i];
        }
        dp[1][0] = 1;
        for ( int i = 1 ; i <= m ; i++ ) {
            for ( int j = 1 ; j <= 90000 ; j++ ) {
                if ( b[i] > j ) {
                    continue;
                }
                dp[2][j] = max( dp[2][j] , dp[1][j-b[i]] );
            }
            for ( int j = 0 ; j <= 90000 ; j++ ) {
                dp[1][j] = dp[2][j];
                dp[2][j] = 0;
            }
        }
        long long ans = -1;
        for ( int i = sum ; i <= 90000 ; i++ ) {
            if ( dp[1][i] == 1 ) {
                ans = i;
                break;
            }
        }
        if ( ans == -1 ) {
            cout << "Impossible";
        }
        else {
            cout << ans - sum;
        }
    }
}
# Verdict Execution time Memory Grader output
1 Incorrect 2 ms 7256 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 2 ms 7256 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 44 ms 7256 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 1 ms 4444 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 2 ms 7256 KB Output isn't correct
2 Halted 0 ms 0 KB -