Submission #987299

# Submission time Handle Problem Language Result Execution time Memory
987299 2024-05-22T14:11:34 Z MateiKing80 Shopping Plans (CCO20_day2problem3) C++14
5 / 25
1014 ms 722524 KB
#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 time Memory Grader output
1 Correct 372 ms 637632 KB Output is correct
2 Correct 291 ms 536232 KB Output is correct
3 Correct 79 ms 152004 KB Output is correct
4 Correct 63 ms 107720 KB Output is correct
5 Correct 95 ms 160608 KB Output is correct
6 Correct 54 ms 81352 KB Output is correct
7 Correct 34 ms 48860 KB Output is correct
8 Correct 4 ms 5212 KB Output is correct
9 Correct 3 ms 5212 KB Output is correct
10 Correct 23 ms 35796 KB Output is correct
11 Correct 3 ms 5212 KB Output is correct
12 Correct 3 ms 5468 KB Output is correct
13 Correct 7 ms 11220 KB Output is correct
14 Correct 99 ms 168008 KB Output is correct
15 Correct 3 ms 5208 KB Output is correct
16 Correct 9 ms 8916 KB Output is correct
17 Correct 98 ms 161648 KB Output is correct
18 Correct 3 ms 5464 KB Output is correct
19 Correct 7 ms 9688 KB Output is correct
20 Correct 163 ms 348328 KB Output is correct
21 Correct 3 ms 5208 KB Output is correct
22 Correct 3 ms 5212 KB Output is correct
23 Correct 5 ms 6104 KB Output is correct
24 Correct 3 ms 5208 KB Output is correct
25 Correct 3 ms 5468 KB Output is correct
26 Correct 112 ms 188476 KB Output is correct
27 Correct 80 ms 130456 KB Output is correct
28 Correct 3 ms 5212 KB Output is correct
# Verdict Execution time Memory Grader output
1 Incorrect 1014 ms 722524 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 372 ms 637632 KB Output is correct
2 Correct 291 ms 536232 KB Output is correct
3 Correct 79 ms 152004 KB Output is correct
4 Correct 63 ms 107720 KB Output is correct
5 Correct 95 ms 160608 KB Output is correct
6 Correct 54 ms 81352 KB Output is correct
7 Correct 34 ms 48860 KB Output is correct
8 Correct 4 ms 5212 KB Output is correct
9 Correct 3 ms 5212 KB Output is correct
10 Correct 23 ms 35796 KB Output is correct
11 Correct 3 ms 5212 KB Output is correct
12 Correct 3 ms 5468 KB Output is correct
13 Correct 7 ms 11220 KB Output is correct
14 Correct 99 ms 168008 KB Output is correct
15 Correct 3 ms 5208 KB Output is correct
16 Correct 9 ms 8916 KB Output is correct
17 Correct 98 ms 161648 KB Output is correct
18 Correct 3 ms 5464 KB Output is correct
19 Correct 7 ms 9688 KB Output is correct
20 Correct 163 ms 348328 KB Output is correct
21 Correct 3 ms 5208 KB Output is correct
22 Correct 3 ms 5212 KB Output is correct
23 Correct 5 ms 6104 KB Output is correct
24 Correct 3 ms 5208 KB Output is correct
25 Correct 3 ms 5468 KB Output is correct
26 Correct 112 ms 188476 KB Output is correct
27 Correct 80 ms 130456 KB Output is correct
28 Correct 3 ms 5212 KB Output is correct
29 Incorrect 1014 ms 722524 KB Output isn't correct
30 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 5 ms 5724 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 372 ms 637632 KB Output is correct
2 Correct 291 ms 536232 KB Output is correct
3 Correct 79 ms 152004 KB Output is correct
4 Correct 63 ms 107720 KB Output is correct
5 Correct 95 ms 160608 KB Output is correct
6 Correct 54 ms 81352 KB Output is correct
7 Correct 34 ms 48860 KB Output is correct
8 Correct 4 ms 5212 KB Output is correct
9 Correct 3 ms 5212 KB Output is correct
10 Correct 23 ms 35796 KB Output is correct
11 Correct 3 ms 5212 KB Output is correct
12 Correct 3 ms 5468 KB Output is correct
13 Correct 7 ms 11220 KB Output is correct
14 Correct 99 ms 168008 KB Output is correct
15 Correct 3 ms 5208 KB Output is correct
16 Correct 9 ms 8916 KB Output is correct
17 Correct 98 ms 161648 KB Output is correct
18 Correct 3 ms 5464 KB Output is correct
19 Correct 7 ms 9688 KB Output is correct
20 Correct 163 ms 348328 KB Output is correct
21 Correct 3 ms 5208 KB Output is correct
22 Correct 3 ms 5212 KB Output is correct
23 Correct 5 ms 6104 KB Output is correct
24 Correct 3 ms 5208 KB Output is correct
25 Correct 3 ms 5468 KB Output is correct
26 Correct 112 ms 188476 KB Output is correct
27 Correct 80 ms 130456 KB Output is correct
28 Correct 3 ms 5212 KB Output is correct
29 Incorrect 1014 ms 722524 KB Output isn't correct
30 Halted 0 ms 0 KB -