답안 #925642

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
925642 2024-02-12T06:47:24 Z vjudge1 Kitchen (BOI19_kitchen) C++17
0 / 100
1000 ms 348 KB
/*
no more temmy :(
*/

#include<bits/stdc++.h>
using namespace std;
#pragma GCC optimize("O3,unroll-loops")
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp> 
using namespace __gnu_pbds;
// #include<icecream.hpp>
// using namespace icecream;
#define ll long long
#define int ll
#define ld long double
#define y1 cheza
#define imp cout<<"Impossible\n"
// mt19937 rng(1983413);
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
template<class T> using ordered_set = tree<T,null_type,less<T>,rb_tree_tag,tree_order_statistics_node_update>;
const int N=500;
const int M=1e6;
const int B=317;
const int mod=998244353;
const int INF=1e18;
const int lg=64;
const int dx[]={1,-1,0,0};
const int dy[]={0,0,1,-1};
const double eps=1e-9;
int n,m,k;
int a[N];
int b[N];
int w[N];
int c[N];
int d[N];
void test(){
    cin>>n>>m>>k;
    for(int i=1;i<=n;i++){
        cin>>a[i];
    }
    for(int i=1;i<=m;i++){
        cin>>b[i];
    }
    int res=INF;
    for(int i=0;i<(1ll<<m);i++){
        for(int j=1;j<=n;j++){
            c[j]=a[j];
            d[j]=k;
        }
        for(int j=1;j<=m;j++){
            w[j]=b[j];
        }
        for(int j=0;j<m;j++){
            if((1ll<<j)&(i)){
                set<pair<int,int>>s;
                for(int u=1;u<=n;u++){
                    if(c[u]>0)
                    s.insert({-d[u],u});
                }
                while(s.size()&&w[j+1]>0){
                    auto [x,y]=(*s.begin());
                    s.erase(s.begin());
                    d[y]--;
                    c[y]--;
                    w[j+1]--;
                }
                if(w[j+1]>0){
                    for(int u=1;u<=n;u++){
                        if(c[u]>0){
                            int d=min(w[j+1],c[u]);
                            w[j+1]-=d;
                            c[u]-=d;
                        }
                    }
                }
            }
        }
        int ans=1;
        for(int i=1;i<=n;i++){
            // cout<<c[i]<<' '<<d[i]<<'\n';
            if(c[i]!=0||d[i]>0){
                ans=0;
            }
        }
        if(ans){
            int sum=0;
            for(int i=1;i<=n;i++){
                sum+=a[i];
            }
            for(int j=0;j<m;j++){
                if((1ll<<j)&(i)){
                    sum-=b[j+1];
                }
            }
            sum=abs(sum);
            res=min(sum,res);
        }
    }
    if(res==INF){
        imp;
        return;
    }
    cout<<res<<'\n';

}
/*

*/  
 
signed main(){
    // ic.prefix("debug->| ");
    // freopen("input.txt","r",stdin);
    // freopen("output.txt","w",stdout);

    ios_base::sync_with_stdio(false);
    cin.tie(nullptr);
    // cout.tie(nullptr);
    long long t2=1;
    //  cin>>t2;
    for(int i=1;i<=t2;i++){
        test();
    }
    
    return 0;
 
}
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Incorrect 0 ms 348 KB Output isn't correct
5 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Incorrect 0 ms 348 KB Output isn't correct
5 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 8 ms 344 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Execution timed out 1053 ms 348 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Incorrect 0 ms 348 KB Output isn't correct
5 Halted 0 ms 0 KB -