답안 #862299

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
862299 2023-10-18T03:16:18 Z iskhakkutbilim Kitchen (BOI19_kitchen) C++17
0 / 100
1 ms 456 KB
#include <bits/stdc++.h>
using namespace std;

#define int long long
#define ff first
#define ss second
#define all(a) a.begin(), a.end()


int n, m, k; 
vector<int> a, b;

main(){
   ios::sync_with_stdio(0);
   cin.tie(0); cout.tie(0);
	cin >> n >> m >> k;
	a.resize(n);
	for(auto &e : a) cin >> e;
	b.resize(m);
	for(auto &e : b) cin >> e;
	
	multiset<int> st;
	for(auto e : b) st.insert(e);
	
	sort(all(a));
	int ans = 0;
	int all = 0;
	for(auto &x : a){
		int mn = INT_MAX, ans_mask = -1;
		for(int mask = 0; mask < (1<<(int)b.size()); mask++){
			if(__builtin_popcount(mask) != k) continue;
			int sum = 0, ok = 0;
			for(int i = 0;i < b.size(); i++){
				if(mask & (1<<i)){
					if(b[i] <= 0){
						ok = 1;
						break;
					}
					sum+= b[i];
				}
			}
			if(sum >= x && !ok){
				if(mn > sum){
					mn = sum;
					ans_mask = mask;
				}
			}
		}
		if(ans_mask == -1 || x < k){
			cout << "impossible";
			return 0;
		}
		for(int i = 0;i < b.size(); i++){
			if(ans_mask & (1<<i)){
				b[i]--, x--;
			}
		}
		all|= ans_mask;
		for(int i = 0;i < b.size(); i++){
			if(ans_mask & (1<<i)){
				if(b[i] >= x){
					b[i]-= x;
					x = 0;
				}else if(x > b[i]){
					x-= b[i];
					b[i] = 0;
				}
			}
		}
	}
	for(auto x : a){
		if(x != 0){
			cout << "impossible";
			return 0;
		}
	}
	for(int i = 0;i < b.size(); i++){
		if(all & (1<<i)){
			ans+= b[i];
		}
	}
	cout << ans;
	return 0;
}

Compilation message

kitchen.cpp:13:1: warning: ISO C++ forbids declaration of 'main' with no type [-Wreturn-type]
   13 | main(){
      | ^~~~
kitchen.cpp: In function 'int main()':
kitchen.cpp:33:20: warning: comparison of integer expressions of different signedness: 'long long int' and 'std::vector<long long int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   33 |    for(int i = 0;i < b.size(); i++){
      |                  ~~^~~~~~~~~~
kitchen.cpp:53:19: warning: comparison of integer expressions of different signedness: 'long long int' and 'std::vector<long long int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   53 |   for(int i = 0;i < b.size(); i++){
      |                 ~~^~~~~~~~~~
kitchen.cpp:59:19: warning: comparison of integer expressions of different signedness: 'long long int' and 'std::vector<long long int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   59 |   for(int i = 0;i < b.size(); i++){
      |                 ~~^~~~~~~~~~
kitchen.cpp:77:18: warning: comparison of integer expressions of different signedness: 'long long int' and 'std::vector<long long int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   77 |  for(int i = 0;i < b.size(); i++){
      |                ~~^~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 348 KB Output is correct
2 Incorrect 0 ms 456 KB Output isn't correct
3 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 348 KB Output is correct
2 Incorrect 0 ms 456 KB Output isn't correct
3 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 1 ms 348 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 0 ms 348 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 348 KB Output is correct
2 Incorrect 0 ms 456 KB Output isn't correct
3 Halted 0 ms 0 KB -