#define fast ios_base::sync_with_stdio(0),cin.tie(0),cout.tie(0)
#define It it=se.begin();it!=se.end();it++
#define mem(dp,i) memset(dp,i,sizeof(dp))
#define all(x) begin(x),end(x)
#define unmap unordered_map
#define pii pair<int,int>
#include <bits/stdc++.h>
#define pll pair<ll,ll>
#define vll vector<ll>
#define vi vector<int>
#define ld long double
#define ll long long
#define pb push_back
#define sh short int
#define mid (l+r)/2
#define S second
#define F first
#define sqr 447
using namespace std;
const int inf = 1e9+9;
const int mod = 1e9+7;
const ld pai=acos(-1);
int n,m,k;
int a[309];
int b[309];
bool add(multiset < int > &s){
while(!s.empty() && *s.begin() == 0){
s.erase(s.find(0));
}
if(s.size() < k) return 0;
vector < int > v;
for(int i=0;i<k;i++){
int x = *s.rbegin();
s.erase(s.find(x));
v.pb(x-1);
}
for(auto u:v){
s.insert(u);
}
return 1;
}
int main(){
fast,cin>>n>>m>>k;
for(int i=0;i<n;i++) cin>>a[i];
for(int i=0;i<m;i++) cin>>b[i];
sort(a,a+n);
if(a[0] < k){
cout<<"Impossible"<<endl;
return 0;
}
multiset < int > se;
for(int i=0;i<m;i++){
se.insert(b[i]);
}
for(int i=0;i<n;i++){
if(!add(se)){
cout<<"Impossible"<<endl;
return 0;
}
a[i] -= k;
}
int sum1 = 0;
for(int i=0;i<n;i++){
sum1 += a[i];
}
int sum2 = 0;
while(!se.empty()){
int x = *se.begin();
se.erase(se.find(x));
sum2 += x;
}
if(sum1 > sum2){
cout<<"Impossible"<<endl;
return 0;
}
cout<<sum2-sum1<<endl;
}
Compilation message
kitchen.cpp: In function 'bool add(std::multiset<int>&)':
kitchen.cpp:30:17: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
if(s.size() < k) return 0;
~~~~~~~~~^~~
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
0 ms |
384 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
0 ms |
384 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
1 ms |
384 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
0 ms |
384 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
0 ms |
384 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |