Submission #277760

# Submission time Handle Problem Language Result Execution time Memory
277760 2020-08-21T07:13:46 Z 최은수(#5116) Shopping Plans (CCO20_day2problem3) C++17
5 / 25
1232 ms 721352 KB
#include<iostream>
#include<vector>
#include<queue>
#include<algorithm>
#define ep emplace
#define eb emplace_back
#define fi first
#define se second
#define all(x) (x).begin(),(x).end()
using namespace std;
typedef long long ll;
typedef pair<int,int>pi;
typedef pair<ll,ll>pl;
const int inf=1e9+7;
const ll INF=1e18;
typedef pair<ll,vector<int> >typ;
vector<int>tv[200010];
struct cmp
{
    bool operator()(const typ&x,const typ&y)const
    {
        return x.fi>y.fi;
    }
};
priority_queue<typ,vector<typ>,cmp>pq;
int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(nullptr);
    int n,m,k;
    cin>>n>>m>>k;
    for(int i=0;i<n;i++)
    {
        int a,c;
        cin>>a>>c;
        tv[a-1].eb(c);
    }
    ll all=0;
    vector<ll>sv;
    for(int i=0;i<12;i++)
        sv.eb(inf);
    for(int i=0;i<m;i++)
    {
        if(tv[i].empty())
        {
            for(int j=0;j<k;j++)
                cout<<"-1\n";
            cout.flush();
            return 0;
        }
        sort(all(tv[i]));
        all+=tv[i][0];
        if((int)tv[i].size()>1)
            sv.eb(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.ep(all,zv);
    int c=0;
    while(!pq.empty()&&c<k)
    {
        ll cost=pq.top().fi;
        vector<int>cur=pq.top().se;
        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.ep(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";
    cout.flush();
    return 0;
}
# Verdict Execution time Memory Grader output
1 Correct 445 ms 637516 KB Output is correct
2 Correct 399 ms 536156 KB Output is correct
3 Correct 121 ms 152176 KB Output is correct
4 Correct 92 ms 107752 KB Output is correct
5 Correct 130 ms 160492 KB Output is correct
6 Correct 72 ms 81264 KB Output is correct
7 Correct 47 ms 48748 KB Output is correct
8 Correct 6 ms 5248 KB Output is correct
9 Correct 6 ms 5120 KB Output is correct
10 Correct 34 ms 35836 KB Output is correct
11 Correct 5 ms 5120 KB Output is correct
12 Correct 6 ms 5376 KB Output is correct
13 Correct 12 ms 11128 KB Output is correct
14 Correct 125 ms 167944 KB Output is correct
15 Correct 5 ms 5248 KB Output is correct
16 Correct 10 ms 8696 KB Output is correct
17 Correct 131 ms 161480 KB Output is correct
18 Correct 6 ms 5504 KB Output is correct
19 Correct 10 ms 9724 KB Output is correct
20 Correct 248 ms 348396 KB Output is correct
21 Correct 5 ms 5120 KB Output is correct
22 Correct 6 ms 5120 KB Output is correct
23 Correct 9 ms 6012 KB Output is correct
24 Correct 6 ms 5248 KB Output is correct
25 Correct 6 ms 5376 KB Output is correct
26 Correct 142 ms 188392 KB Output is correct
27 Correct 93 ms 130532 KB Output is correct
28 Correct 6 ms 5248 KB Output is correct
# Verdict Execution time Memory Grader output
1 Incorrect 1232 ms 721352 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 445 ms 637516 KB Output is correct
2 Correct 399 ms 536156 KB Output is correct
3 Correct 121 ms 152176 KB Output is correct
4 Correct 92 ms 107752 KB Output is correct
5 Correct 130 ms 160492 KB Output is correct
6 Correct 72 ms 81264 KB Output is correct
7 Correct 47 ms 48748 KB Output is correct
8 Correct 6 ms 5248 KB Output is correct
9 Correct 6 ms 5120 KB Output is correct
10 Correct 34 ms 35836 KB Output is correct
11 Correct 5 ms 5120 KB Output is correct
12 Correct 6 ms 5376 KB Output is correct
13 Correct 12 ms 11128 KB Output is correct
14 Correct 125 ms 167944 KB Output is correct
15 Correct 5 ms 5248 KB Output is correct
16 Correct 10 ms 8696 KB Output is correct
17 Correct 131 ms 161480 KB Output is correct
18 Correct 6 ms 5504 KB Output is correct
19 Correct 10 ms 9724 KB Output is correct
20 Correct 248 ms 348396 KB Output is correct
21 Correct 5 ms 5120 KB Output is correct
22 Correct 6 ms 5120 KB Output is correct
23 Correct 9 ms 6012 KB Output is correct
24 Correct 6 ms 5248 KB Output is correct
25 Correct 6 ms 5376 KB Output is correct
26 Correct 142 ms 188392 KB Output is correct
27 Correct 93 ms 130532 KB Output is correct
28 Correct 6 ms 5248 KB Output is correct
29 Incorrect 1232 ms 721352 KB Output isn't correct
30 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 10 ms 5632 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 445 ms 637516 KB Output is correct
2 Correct 399 ms 536156 KB Output is correct
3 Correct 121 ms 152176 KB Output is correct
4 Correct 92 ms 107752 KB Output is correct
5 Correct 130 ms 160492 KB Output is correct
6 Correct 72 ms 81264 KB Output is correct
7 Correct 47 ms 48748 KB Output is correct
8 Correct 6 ms 5248 KB Output is correct
9 Correct 6 ms 5120 KB Output is correct
10 Correct 34 ms 35836 KB Output is correct
11 Correct 5 ms 5120 KB Output is correct
12 Correct 6 ms 5376 KB Output is correct
13 Correct 12 ms 11128 KB Output is correct
14 Correct 125 ms 167944 KB Output is correct
15 Correct 5 ms 5248 KB Output is correct
16 Correct 10 ms 8696 KB Output is correct
17 Correct 131 ms 161480 KB Output is correct
18 Correct 6 ms 5504 KB Output is correct
19 Correct 10 ms 9724 KB Output is correct
20 Correct 248 ms 348396 KB Output is correct
21 Correct 5 ms 5120 KB Output is correct
22 Correct 6 ms 5120 KB Output is correct
23 Correct 9 ms 6012 KB Output is correct
24 Correct 6 ms 5248 KB Output is correct
25 Correct 6 ms 5376 KB Output is correct
26 Correct 142 ms 188392 KB Output is correct
27 Correct 93 ms 130532 KB Output is correct
28 Correct 6 ms 5248 KB Output is correct
29 Incorrect 1232 ms 721352 KB Output isn't correct
30 Halted 0 ms 0 KB -