제출 #987299

#제출 시각아이디문제언어결과실행 시간메모리
987299MateiKing80Shopping Plans (CCO20_day2problem3)C++14
5 / 25
1014 ms722524 KiB
#include<bits/stdc++.h>

using namespace std;

#define fr first
#define sc second
#define all(x) (x).begin(),(x).end()
using ll = long long;
#define pii pair<int, int>;
const int inf=1e9+7;
const ll INF=1e18;
#define typ pair<ll, vector<int>>

vector<int> tv[200010];
struct cmp
{
    bool operator()(const typ &x,const typ &y)const
    {
        return x.fr > y.fr;
    }
};
priority_queue<typ, vector<typ>, cmp> pq;
int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    int n, m, k;
    cin>> n >> m >> k;
    for(int i = 0; i < n; i ++)
    {
        int a , c;
        cin >> a >> c;
        tv[a - 1].emplace_back(c);
    }
    ll all = 0;
    vector<ll> sv;
    for(int i = 0; i < 12; i ++)
        sv.emplace_back(inf);
    for(int i = 0; i < m; i ++)
    {
        if(tv[i].empty())
        {
            for(int j = 0; j < k; j ++)
                cout << "-1\n";
            return 0;
        }
        sort(all(tv[i]));
        all += tv[i][0];
        if((int)tv[i].size() > 1)
            sv.emplace_back(tv[i][1] - tv[i][0]);
    }
    sort(all(sv));
    ll al2 = all;
    for(int i = 0; i < 12; i ++)
        al2 += sv[i];
    vector<int> zv(m, 0);
    pq.emplace(all, zv);
    int c = 0;
    while(!pq.empty() && c < k)
    {
        ll cost = pq.top().fr;
        vector<int> cur = pq.top().sc;
        pq.pop();
        cout << cost << '\n';
        c ++;
        int cnt = 1;
        for(int j = 0; j < m; j ++)
            cnt *= cur[j] + 1;
        for(int j = 0; j < m; j ++)
        {
            if(cur[j] + 1 < (int)tv[j].size())
            {
                cost -= tv[j][cur[j]];
                cost += tv[j][++ cur[j]];
                if(cost < al2)
                pq.emplace(cost, cur);
                cost -= tv[j][cur[j]];
                cost += tv[j][-- cur[j]];
            }
            if(cur[j] != 0)
                break;
        }
    }
    for(int i = c; i < k; i ++)
        cout<<"-1\n";
    return 0;
}
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...