Submission #570446

# Submission time Handle Problem Language Result Execution time Memory
570446 2022-05-30T01:39:18 Z cpp219 Kitchen (BOI19_kitchen) C++17
21 / 100
362 ms 115808 KB
#include<bits/stdc++.h>
#define ll int
#define ld long double
#define fs first
#define sc second
#define debug(y) cout<<y,exit(0)
using namespace std;
typedef pair<ll,ll> LL;
const ll N = 300 + 9;
const ll inf = 1e9 + 7;

ll n,m,k,a[N],dp[N][N*N],b[N],ans = inf,sum;

void endgame(){
    cout<<"Impossible"; exit(0);
}

ll f(ll pos,ll total){
    if (!total || !pos) return 0;
    ll &res = dp[pos][total];
    if (res != -1) return res;
    res = f(pos - 1,total);
    if (total >= b[pos]) res = max(res,f(pos - 1,total - b[pos]) + min(b[pos],n));
    return res;
}

int main(){
    ios_base::sync_with_stdio(NULL); cin.tie(0); cout.tie(0);
    #define task "tst"
    if (fopen(task".inp","r")){
        freopen(task".inp","r",stdin);
        //freopen(task".out","w",stdout);
    }
    cin>>n>>m>>k;
    for (ll i = 1;i <= n;i++) cin>>a[i],sum += a[i];
    for (ll i = 1;i <= m;i++) cin>>b[i];
    if (*min_element(a + 1,a + n + 1) < k) endgame();
    memset(dp,-1,sizeof(dp)); //debug(f(1,5));
    for (ll i = sum;i < N*N;i++)
        if (f(m,i) >= n*k) ans = min(ans,i);
    if (ans == inf) endgame();
    debug(ans - sum);
}
/// be confident


Compilation message

kitchen.cpp: In function 'int main()':
kitchen.cpp:31:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   31 |         freopen(task".inp","r",stdin);
      |         ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 48 ms 115788 KB Output is correct
2 Incorrect 45 ms 115776 KB Output isn't correct
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 48 ms 115788 KB Output is correct
2 Incorrect 45 ms 115776 KB Output isn't correct
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 362 ms 115796 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 90 ms 115788 KB Output is correct
2 Correct 91 ms 115776 KB Output is correct
3 Correct 94 ms 115660 KB Output is correct
4 Correct 94 ms 115808 KB Output is correct
5 Correct 1 ms 212 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 48 ms 115788 KB Output is correct
2 Incorrect 45 ms 115776 KB Output isn't correct
3 Halted 0 ms 0 KB -