답안 #925976

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
925976 2024-02-12T12:12:59 Z vjudge1 Kitchen (BOI19_kitchen) C++17
100 / 100
28 ms 8792 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;
pair <long long , long long> pr[N];
long long a[N] , b[N];
long long dp[4][100005];

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;
    int can = 0;
    for ( int i = 1 ; i <= n ; i++ ) {
        cin >> a[i];
        if ( a[i] < k ) {
            can = 1;
        }
    }
    for ( int i = 1 ; i <= m ; i++ ) {
        cin >> b[i];
        pr[i].first = b[i];
        pr[i].second = min( b[i] , n );
    }
    if ( k > m || can == 1 ) {
        cout << "Impossible";
        return 0;
    }
    for ( int i = 0 ; i <= 90000 ; i++ ) {
        dp[1][i] = -INF;
        dp[2][i] = -INF;
    }
    dp[1][0] = 0;
    sort( pr + 1 , pr + 1 + m );
    for ( int i = 1 ; i <= m ; i++ ) {
        for ( int j = pr[i].first ; j <= 90000 ; j++ ) {
            if ( dp[1][j-pr[i].first] == -INF ) {
                continue;
            }
            else {
                dp[2][j] = max( dp[1][j-pr[i].first] + pr[i].second , dp[2][j] );
            }
        }
        for ( int j = 0 ; j <= 90000 ; j++ ) {
            dp[1][j] = max( dp[1][j] , dp[2][j] );
            dp[2][j] = -INF;
        }
    }
    long long sum = 0;
    for ( int i = 1 ; i <= n ; i++ ) {
        sum += a[i];
    }
    long long ans = -1;
    for ( int i = sum ; i <= 90000 ; i++ ) {
        if ( dp[1][i] >= n * k ) {
            ans = i - sum;
            break;
        }
    }
    if ( ans == -1 ) {
        cout << "Impossible";
    }
    else {
        cout << ans;
    }
}
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 8540 KB Output is correct
2 Correct 2 ms 8664 KB Output is correct
3 Correct 1 ms 8540 KB Output is correct
4 Correct 2 ms 8540 KB Output is correct
5 Correct 1 ms 8540 KB Output is correct
6 Correct 1 ms 6492 KB Output is correct
7 Correct 1 ms 6492 KB Output is correct
8 Correct 2 ms 8540 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 8540 KB Output is correct
2 Correct 2 ms 8664 KB Output is correct
3 Correct 1 ms 8540 KB Output is correct
4 Correct 2 ms 8540 KB Output is correct
5 Correct 1 ms 8540 KB Output is correct
6 Correct 1 ms 6492 KB Output is correct
7 Correct 1 ms 6492 KB Output is correct
8 Correct 2 ms 8540 KB Output is correct
9 Correct 2 ms 8540 KB Output is correct
10 Correct 2 ms 8540 KB Output is correct
11 Correct 2 ms 8540 KB Output is correct
12 Correct 2 ms 8540 KB Output is correct
13 Correct 2 ms 8540 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 22 ms 8540 KB Output is correct
2 Correct 24 ms 8672 KB Output is correct
3 Correct 25 ms 8540 KB Output is correct
4 Correct 28 ms 8540 KB Output is correct
5 Correct 27 ms 8540 KB Output is correct
6 Correct 17 ms 8536 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 5 ms 8536 KB Output is correct
2 Correct 4 ms 8540 KB Output is correct
3 Correct 5 ms 8540 KB Output is correct
4 Correct 4 ms 8664 KB Output is correct
5 Correct 1 ms 6492 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 8540 KB Output is correct
2 Correct 2 ms 8664 KB Output is correct
3 Correct 1 ms 8540 KB Output is correct
4 Correct 2 ms 8540 KB Output is correct
5 Correct 1 ms 8540 KB Output is correct
6 Correct 1 ms 6492 KB Output is correct
7 Correct 1 ms 6492 KB Output is correct
8 Correct 2 ms 8540 KB Output is correct
9 Correct 2 ms 8540 KB Output is correct
10 Correct 2 ms 8540 KB Output is correct
11 Correct 2 ms 8540 KB Output is correct
12 Correct 2 ms 8540 KB Output is correct
13 Correct 2 ms 8540 KB Output is correct
14 Correct 22 ms 8540 KB Output is correct
15 Correct 24 ms 8672 KB Output is correct
16 Correct 25 ms 8540 KB Output is correct
17 Correct 28 ms 8540 KB Output is correct
18 Correct 27 ms 8540 KB Output is correct
19 Correct 17 ms 8536 KB Output is correct
20 Correct 5 ms 8536 KB Output is correct
21 Correct 4 ms 8540 KB Output is correct
22 Correct 5 ms 8540 KB Output is correct
23 Correct 4 ms 8664 KB Output is correct
24 Correct 1 ms 6492 KB Output is correct
25 Correct 18 ms 8540 KB Output is correct
26 Correct 20 ms 8792 KB Output is correct
27 Correct 14 ms 8740 KB Output is correct
28 Correct 21 ms 8536 KB Output is correct
29 Correct 23 ms 8536 KB Output is correct
30 Correct 28 ms 8540 KB Output is correct