답안 #1004325

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
1004325 2024-06-21T07:45:05 Z vjudge1 Kitchen (BOI19_kitchen) C++17
0 / 100
0 ms 348 KB
#pragma GCC optimize("-O3")
#include<bits/stdc++.h>
#include<ext/pb_ds/assoc_container.hpp>
#include<ext/pb_ds/tree_policy.hpp>
#define ll long long
#define ld long double
#define vl vector<ll>
#define vi vector<int>
#define pii pair<int, int>
#define pll pair<ll, ll>
#define all(v) v.begin(), v.end()
#define rall(v) v.rbegin(), v.rend()
#define pb push_back
#define p_b pop_back
#define f first
#define s second
using namespace std;
using namespace __gnu_pbds;
typedef tree<int, null_type, less_equal<int>, rb_tree_tag, tree_order_statistics_node_update> ordered_set;
void solve()
{
    ll n, m, k, i, j;
    cin >> n >> m >> k;
    ll a[n+5], b[m+5], c[m+5];
    for(i = 1; i <= n; i++)
        cin >> a[i];
    for(i = 1; i <= m; i++){
        cin >> b[i];
        c[i] = b[i];
    }
    ll sum = 0;
    for(i = 1; i <= n; i++)
        sum += a[i];
    sort(a+1, a+n+1);
    sort(b+1, b+n+1);
    sum = 0;
    j = 1;
    for(i = n; i >= 1; i--)
    {
        while(a[i] && j <= m){
            ll f = min(a[i], b[j]);
            a[i] -= f;
            b[j] -= f;
            if(b[j] == 0)
                j++;
        }
    }
    ll sum1 = 0, sum2 = 0;
    for(i = 1; i <= n; i++)
        sum1 += a[i];
    if(sum1 > 0)
        cout << "Impossible\n";
    else
    {
        ll res = 0;
        for(i = 1; i <= m; i++)
        {
            if(c[i] != b[i] && b[i] > 0)
                res += (c[i] - b[i]);
        }
        cout << res << "\n";
    }
}
int main()
{
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
    ll tests = 1;
    //cin >> tests;
    while(tests--)
    {
        solve();
    }
}

Compilation message

kitchen.cpp: In function 'void solve()':
kitchen.cpp:48:18: warning: unused variable 'sum2' [-Wunused-variable]
   48 |     ll sum1 = 0, sum2 = 0;
      |                  ^~~~
# 결과 실행 시간 메모리 Grader output
1 Incorrect 0 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 Incorrect 0 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 Incorrect 0 ms 348 KB Output isn't correct
2 Halted 0 ms 0 KB -