Submission #726920

# Submission time Handle Problem Language Result Execution time Memory
726920 2023-04-19T14:54:17 Z TimDee Kitchen (BOI19_kitchen) C++17
100 / 100
188 ms 3712 KB
#include <bits/stdc++.h>
using namespace std;

#pragma GCC optimize("O3")
#pragma GCC optimize("Ofast")
#pragma GCC target("avx2,popcnt")

//#define int long long
#define forn(i,n) for(int i=0;i<n;++i)
#define pb push_back
#define all(x) x.begin(),x.end()
#define rall(x) x.rbegin(),x.rend()
#define f first
#define s second
#define pi pair<int,int>

#define vii(a,n) vector<int>a(n);forn(i,n)cin>>a[i];

const int inf = 1e9;
const int mod = 998244353;

void imp() {
	cout<<"Impossible";
	exit(0);
}
const int S=9e4;
const int M=300;
bitset<S+1> dp[M+1];

void solve() {

	int n,m,k; cin>>n>>m>>k;
	vii(a,n);
	vii(b,m);

	int s=0, s2=0;
	for(auto&x:a) s+=x;
	for(auto&x:b) s2+=x;
	if (s2<s) {
		imp();
	}
	forn(i,n) if (a[i]<k) imp();
	if (m<k) imp();

	dp[0][0]=1;

	sort(all(b));
	for(auto&x:b) {
		if (x<n) {
			for (int i=s2-x; i>=0; --i) {
				int j1=min(i/n,m);
				int j2=min((i+x)/n,m);
				if (dp[j1][i]) dp[j2][i+x]=1;
			}
		} else {
			for (int j=m-1; j>=0; --j) {
				dp[j+1]|=dp[j]<<x;
			}
		}
	}

	for (int i=s; i<=s2; ++i) {
		for (int j=k; j<=m; ++j) {
			if (dp[j][i]) {
				cout<<i-s<<'\n';
				return;
			}
		}
	}
	imp();

}

int32_t main() {
	ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
	solve();
}
# Verdict Execution time Memory Grader output
1 Correct 1 ms 340 KB Output is correct
2 Correct 1 ms 340 KB Output is correct
3 Correct 1 ms 340 KB Output is correct
4 Correct 1 ms 340 KB Output is correct
5 Correct 1 ms 340 KB Output is correct
6 Correct 1 ms 340 KB Output is correct
7 Correct 1 ms 340 KB Output is correct
8 Correct 1 ms 212 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 340 KB Output is correct
2 Correct 1 ms 340 KB Output is correct
3 Correct 1 ms 340 KB Output is correct
4 Correct 1 ms 340 KB Output is correct
5 Correct 1 ms 340 KB Output is correct
6 Correct 1 ms 340 KB Output is correct
7 Correct 1 ms 340 KB Output is correct
8 Correct 1 ms 212 KB Output is correct
9 Correct 1 ms 468 KB Output is correct
10 Correct 1 ms 468 KB Output is correct
11 Correct 1 ms 468 KB Output is correct
12 Correct 0 ms 340 KB Output is correct
13 Correct 1 ms 340 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 99 ms 1200 KB Output is correct
2 Correct 92 ms 1128 KB Output is correct
3 Correct 122 ms 3524 KB Output is correct
4 Correct 182 ms 3648 KB Output is correct
5 Correct 1 ms 340 KB Output is correct
6 Correct 71 ms 956 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 5 ms 724 KB Output is correct
2 Correct 3 ms 724 KB Output is correct
3 Correct 1 ms 724 KB Output is correct
4 Correct 2 ms 724 KB Output is correct
5 Correct 0 ms 340 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 340 KB Output is correct
2 Correct 1 ms 340 KB Output is correct
3 Correct 1 ms 340 KB Output is correct
4 Correct 1 ms 340 KB Output is correct
5 Correct 1 ms 340 KB Output is correct
6 Correct 1 ms 340 KB Output is correct
7 Correct 1 ms 340 KB Output is correct
8 Correct 1 ms 212 KB Output is correct
9 Correct 1 ms 468 KB Output is correct
10 Correct 1 ms 468 KB Output is correct
11 Correct 1 ms 468 KB Output is correct
12 Correct 0 ms 340 KB Output is correct
13 Correct 1 ms 340 KB Output is correct
14 Correct 99 ms 1200 KB Output is correct
15 Correct 92 ms 1128 KB Output is correct
16 Correct 122 ms 3524 KB Output is correct
17 Correct 182 ms 3648 KB Output is correct
18 Correct 1 ms 340 KB Output is correct
19 Correct 71 ms 956 KB Output is correct
20 Correct 5 ms 724 KB Output is correct
21 Correct 3 ms 724 KB Output is correct
22 Correct 1 ms 724 KB Output is correct
23 Correct 2 ms 724 KB Output is correct
24 Correct 0 ms 340 KB Output is correct
25 Correct 103 ms 2656 KB Output is correct
26 Correct 138 ms 2996 KB Output is correct
27 Correct 46 ms 2092 KB Output is correct
28 Correct 111 ms 3016 KB Output is correct
29 Correct 142 ms 3096 KB Output is correct
30 Correct 188 ms 3712 KB Output is correct