답안 #925870

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
925870 2024-02-12T10:16:25 Z vjudge1 Kitchen (BOI19_kitchen) C++17
0 / 100
43 ms 4720 KB
#include <bits/stdc++.h>

using namespace std;

#define all(a) a.begin(),a.end()
#define pb push_back
#define vt vector
#define endl '\n'
typedef long long ll;

const ll mod=1e9+7;
const ll inf=mod;
const int N=5e5+4;

int X[]={0,0,1,-1};
int Y[]={1,-1,0,0};

int n,m,k,a[N],b[N],used[N];

void solve(){
	cin>>n>>m>>k;
	for(int i=1; i<=n; ++i){
		cin>>a[i];
	}
	sort(a+1,a+1+n);
	for(int i=1; i<=m; ++i){
		cin>>b[i];
	}
	if(k==1){
		int sum=0;
		for(int i=1; i<=n; ++i) sum+=a[i];
		used[0]=1;
		for(int i=1; i<=m; ++i){
			for(int j=200000; j>=b[i]; --j) used[j]=max(used[j],used[j-b[i]]);
		}
		int ans=mod;
		for(int i=sum; i<=200000; ++i) if(used[i]) ans=min(ans,abs(i-sum));
		cout<<ans<<endl;
		return;
	}
	if(m<=15){
		for(int mask=0; mask<(1<<m); ++mask){
			vt<int>v;
			for(int i=0; i<m; ++i) if(mask&(1<<i)) v.pb(b[i+1]);
			sort(all(v));
			int val=0,id=1;
			for(int i=0; i<m; ++i){
				int xx=v[i]-val;
				while(id<=n && a[id]<=xx){
					xx-=a[id];
					val+=a[id];
					++id;
				}
				
			}
		}
	}
}

int main(){
	ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
	int tt=1;
	//	cin>>tt;
	while(tt--) {
		solve();
	}
}
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 4696 KB Output is correct
2 Correct 2 ms 4700 KB Output is correct
3 Correct 1 ms 4560 KB Output is correct
4 Incorrect 1 ms 4440 KB Output isn't correct
5 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 4696 KB Output is correct
2 Correct 2 ms 4700 KB Output is correct
3 Correct 1 ms 4560 KB Output is correct
4 Incorrect 1 ms 4440 KB Output isn't correct
5 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 38 ms 4696 KB Output is correct
2 Correct 33 ms 4700 KB Output is correct
3 Correct 43 ms 4700 KB Output is correct
4 Correct 43 ms 4720 KB Output is correct
5 Incorrect 43 ms 4700 KB Output isn't correct
6 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 1 ms 4444 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 4696 KB Output is correct
2 Correct 2 ms 4700 KB Output is correct
3 Correct 1 ms 4560 KB Output is correct
4 Incorrect 1 ms 4440 KB Output isn't correct
5 Halted 0 ms 0 KB -