Submission #726914

# Submission time Handle Problem Language Result Execution time Memory
726914 2023-04-19T14:42:14 Z TimDee Kitchen (BOI19_kitchen) C++17
0 / 100
144 ms 312 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=8;//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();

	//vector<vector<int>> dp(s2+1,vector<int>(m+1,0));
	dp[0][0]=1;

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

	//forn(i,s2+1) {
	//	forn(j,m+1) cout<<dp[j][i]<<' '; cout<<'\n';
	//}

	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 Incorrect 1 ms 212 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 1 ms 212 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 144 ms 312 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 1 ms 212 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 1 ms 212 KB Output isn't correct
2 Halted 0 ms 0 KB -