답안 #987748

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
987748 2024-05-23T14:23:03 Z activedeltorre Shopping Plans (CCO20_day2problem3) C++14
15 / 25
165 ms 33844 KB
#include <iostream>
#include <vector>
#include <queue>
#include <algorithm>

using namespace std;
//ifstream cin("a.in");
//ofstream cout("a.out");
long long inf=1e9+10;
struct node
{
    long long  layer,sum,lst,biti;
};
struct  cmp
{
    bool operator()(node a,node  b)
    {
        return a.sum>b.sum;
    }
};
priority_queue<node,vector<node>,cmp>pq;
vector<long long >arr;
vector<long long >adj[200005];
long long cost[200005];
vector<long long>ord;
bool cmp2(long long a,long long b)
{
    return cost[a]<cost[b];
}
int y[200005];
signed  main()
{
    long long  n,m,k,i,a,b,x;
    long long sum=0;
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cin>>n>>m>>k;
    for(i=1; i<=n; i++)
    {
        cin>>a>>b;
        adj[a].push_back(b);
    }
    long long imp=0,minim=inf,poz=m;
    for(i=1; i<=m; i++)
    {
        cin>>x>>y[i];
        if(x==0)
        {
            adj[i].push_back(0);
        }
        sort(adj[i].begin(),adj[i].end());
        if(adj[i].size()<x)
        {
            for(long long j=1; j<=k; j++)
            {
                cout<<-1<<'\n';
            }
            return 0;
        }
        long long  vkuk=adj[i][0];
        sum+=adj[i][0];
        for(long long  j=0; j<adj[i].size(); j++)
        {
            adj[i][j]-=vkuk;
        }
        if(adj[i].size()>=2)
        {
            cost[i]=adj[i][1];
        }
        else
        {
            cost[i]=inf;
        }
        ord.push_back(i);
    }
    sort(ord.begin(),ord.end(),cmp2);
    m--;
    for(i=0; i<ord.size(); i++)
    {
        if(cost[ord[i]]==inf)
        {
            m=i-1;
            break;
        }
    }
    node curr,curr2;
    cout<<sum<<'\n';
    k--;
    if(m>=0)
    {
        pq.push({0,adj[ord[0]][1],1,1});
        while(pq.size() && k && imp==0)
        {
            curr=pq.top();
            pq.pop();
            k--;
            cout<<curr.sum+sum<<'\n';
            if(curr.lst==1 && curr.layer+1<=m)
            {
                curr2=curr;
                curr2.layer++;
                curr2.biti=1;
                curr2.sum=curr2.sum-adj[ord[curr.layer]][1]+adj[ord[curr.layer+1]][1];
                pq.push(curr2);
            }
            if(curr.layer+1<=m)
            {
                curr2=curr;
                curr2.layer++;
                curr2.lst=1;
                curr2.biti=1;
                curr2.sum=curr2.sum+adj[ord[curr.layer+1]][1];
                pq.push(curr2);
            }
            if(adj[ord[curr.layer]].size()>curr.lst+1 && curr.biti+1<=y[ord[curr.layer]])
            {
                curr2=curr;
                curr2.lst++;
                curr2.biti++;
                curr2.sum+=adj[ord[curr.layer]][curr2.lst];
                pq.push(curr2);
            }
            if(adj[ord[curr.layer]].size()>curr.lst+1)
            {
                curr2=curr;
                curr2.sum=curr.sum-adj[ord[curr.layer]][curr.lst]+adj[ord[curr.layer]][curr.lst+1];
                curr2.lst++;
                pq.push(curr2);
            }
        }
        while(k)
        {
            k--;
            cout<<-1<<'\n';
        }
    }
    return 0;
}
/*
5 2 7
1 5
1 3
2 3
1 6
2 1
1 1
1 1*/

Compilation message

Main.cpp: In function 'int main()':
Main.cpp:52:25: warning: comparison of integer expressions of different signedness: 'std::vector<long long int>::size_type' {aka 'long unsigned int'} and 'long long int' [-Wsign-compare]
   52 |         if(adj[i].size()<x)
      |            ~~~~~~~~~~~~~^~
Main.cpp:62:30: warning: comparison of integer expressions of different signedness: 'long long int' and 'std::vector<long long int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   62 |         for(long long  j=0; j<adj[i].size(); j++)
      |                             ~^~~~~~~~~~~~~~
Main.cpp:78:15: warning: comparison of integer expressions of different signedness: 'long long int' and 'std::vector<long long int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   78 |     for(i=0; i<ord.size(); i++)
      |              ~^~~~~~~~~~~
Main.cpp:115:43: warning: comparison of integer expressions of different signedness: 'std::vector<long long int>::size_type' {aka 'long unsigned int'} and 'long long int' [-Wsign-compare]
  115 |             if(adj[ord[curr.layer]].size()>curr.lst+1 && curr.biti+1<=y[ord[curr.layer]])
      |                ~~~~~~~~~~~~~~~~~~~~~~~~~~~^~~~~~~~~~~
Main.cpp:123:43: warning: comparison of integer expressions of different signedness: 'std::vector<long long int>::size_type' {aka 'long unsigned int'} and 'long long int' [-Wsign-compare]
  123 |             if(adj[ord[curr.layer]].size()>curr.lst+1)
      |                ~~~~~~~~~~~~~~~~~~~~~~~~~~~^~~~~~~~~~~
Main.cpp:43:21: warning: unused variable 'minim' [-Wunused-variable]
   43 |     long long imp=0,minim=inf,poz=m;
      |                     ^~~~~
Main.cpp:43:31: warning: unused variable 'poz' [-Wunused-variable]
   43 |     long long imp=0,minim=inf,poz=m;
      |                               ^~~
# 결과 실행 시간 메모리 Grader output
1 Correct 5 ms 8024 KB Output is correct
2 Correct 4 ms 7768 KB Output is correct
3 Correct 4 ms 7812 KB Output is correct
4 Correct 4 ms 7784 KB Output is correct
5 Correct 4 ms 7772 KB Output is correct
6 Correct 5 ms 7772 KB Output is correct
7 Correct 4 ms 7772 KB Output is correct
8 Correct 4 ms 7728 KB Output is correct
9 Correct 3 ms 7200 KB Output is correct
10 Correct 4 ms 7772 KB Output is correct
11 Correct 3 ms 7260 KB Output is correct
12 Correct 3 ms 7516 KB Output is correct
13 Correct 4 ms 7648 KB Output is correct
14 Correct 4 ms 8028 KB Output is correct
15 Correct 4 ms 7516 KB Output is correct
16 Correct 3 ms 7648 KB Output is correct
17 Correct 4 ms 7728 KB Output is correct
18 Correct 3 ms 7260 KB Output is correct
19 Correct 3 ms 7772 KB Output is correct
20 Correct 4 ms 7772 KB Output is correct
21 Correct 2 ms 7260 KB Output is correct
22 Correct 3 ms 7768 KB Output is correct
23 Correct 4 ms 7768 KB Output is correct
24 Correct 4 ms 7516 KB Output is correct
25 Correct 5 ms 7516 KB Output is correct
26 Correct 4 ms 7764 KB Output is correct
27 Correct 4 ms 7772 KB Output is correct
28 Correct 4 ms 7772 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 47 ms 27112 KB Output is correct
2 Correct 54 ms 25524 KB Output is correct
3 Correct 56 ms 26096 KB Output is correct
4 Correct 49 ms 25792 KB Output is correct
5 Correct 44 ms 17644 KB Output is correct
6 Correct 44 ms 16504 KB Output is correct
7 Correct 48 ms 25276 KB Output is correct
8 Correct 45 ms 24792 KB Output is correct
9 Correct 15 ms 7768 KB Output is correct
10 Correct 58 ms 25768 KB Output is correct
11 Correct 14 ms 7768 KB Output is correct
12 Correct 25 ms 8908 KB Output is correct
13 Correct 53 ms 26772 KB Output is correct
14 Correct 57 ms 26800 KB Output is correct
15 Correct 12 ms 8028 KB Output is correct
16 Correct 49 ms 25280 KB Output is correct
17 Correct 57 ms 25012 KB Output is correct
18 Correct 20 ms 8408 KB Output is correct
19 Correct 53 ms 26808 KB Output is correct
20 Correct 47 ms 25564 KB Output is correct
21 Correct 13 ms 8028 KB Output is correct
22 Correct 50 ms 17136 KB Output is correct
23 Correct 52 ms 26168 KB Output is correct
24 Correct 14 ms 7772 KB Output is correct
25 Correct 14 ms 7772 KB Output is correct
26 Correct 41 ms 17588 KB Output is correct
27 Correct 41 ms 18368 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 5 ms 8024 KB Output is correct
2 Correct 4 ms 7768 KB Output is correct
3 Correct 4 ms 7812 KB Output is correct
4 Correct 4 ms 7784 KB Output is correct
5 Correct 4 ms 7772 KB Output is correct
6 Correct 5 ms 7772 KB Output is correct
7 Correct 4 ms 7772 KB Output is correct
8 Correct 4 ms 7728 KB Output is correct
9 Correct 3 ms 7200 KB Output is correct
10 Correct 4 ms 7772 KB Output is correct
11 Correct 3 ms 7260 KB Output is correct
12 Correct 3 ms 7516 KB Output is correct
13 Correct 4 ms 7648 KB Output is correct
14 Correct 4 ms 8028 KB Output is correct
15 Correct 4 ms 7516 KB Output is correct
16 Correct 3 ms 7648 KB Output is correct
17 Correct 4 ms 7728 KB Output is correct
18 Correct 3 ms 7260 KB Output is correct
19 Correct 3 ms 7772 KB Output is correct
20 Correct 4 ms 7772 KB Output is correct
21 Correct 2 ms 7260 KB Output is correct
22 Correct 3 ms 7768 KB Output is correct
23 Correct 4 ms 7768 KB Output is correct
24 Correct 4 ms 7516 KB Output is correct
25 Correct 5 ms 7516 KB Output is correct
26 Correct 4 ms 7764 KB Output is correct
27 Correct 4 ms 7772 KB Output is correct
28 Correct 4 ms 7772 KB Output is correct
29 Correct 47 ms 27112 KB Output is correct
30 Correct 54 ms 25524 KB Output is correct
31 Correct 56 ms 26096 KB Output is correct
32 Correct 49 ms 25792 KB Output is correct
33 Correct 44 ms 17644 KB Output is correct
34 Correct 44 ms 16504 KB Output is correct
35 Correct 48 ms 25276 KB Output is correct
36 Correct 45 ms 24792 KB Output is correct
37 Correct 15 ms 7768 KB Output is correct
38 Correct 58 ms 25768 KB Output is correct
39 Correct 14 ms 7768 KB Output is correct
40 Correct 25 ms 8908 KB Output is correct
41 Correct 53 ms 26772 KB Output is correct
42 Correct 57 ms 26800 KB Output is correct
43 Correct 12 ms 8028 KB Output is correct
44 Correct 49 ms 25280 KB Output is correct
45 Correct 57 ms 25012 KB Output is correct
46 Correct 20 ms 8408 KB Output is correct
47 Correct 53 ms 26808 KB Output is correct
48 Correct 47 ms 25564 KB Output is correct
49 Correct 13 ms 8028 KB Output is correct
50 Correct 50 ms 17136 KB Output is correct
51 Correct 52 ms 26168 KB Output is correct
52 Correct 14 ms 7772 KB Output is correct
53 Correct 14 ms 7772 KB Output is correct
54 Correct 41 ms 17588 KB Output is correct
55 Correct 41 ms 18368 KB Output is correct
56 Correct 163 ms 32044 KB Output is correct
57 Correct 131 ms 30780 KB Output is correct
58 Correct 159 ms 32100 KB Output is correct
59 Correct 139 ms 31124 KB Output is correct
60 Correct 144 ms 24124 KB Output is correct
61 Correct 155 ms 31668 KB Output is correct
62 Correct 154 ms 28880 KB Output is correct
63 Correct 103 ms 27664 KB Output is correct
64 Correct 60 ms 10952 KB Output is correct
65 Correct 146 ms 30304 KB Output is correct
66 Correct 58 ms 11268 KB Output is correct
67 Correct 46 ms 11272 KB Output is correct
68 Correct 68 ms 27260 KB Output is correct
69 Correct 165 ms 32312 KB Output is correct
70 Correct 20 ms 8028 KB Output is correct
71 Correct 80 ms 27564 KB Output is correct
72 Correct 122 ms 29656 KB Output is correct
73 Correct 12 ms 8024 KB Output is correct
74 Correct 57 ms 18376 KB Output is correct
75 Correct 158 ms 33844 KB Output is correct
76 Correct 12 ms 7780 KB Output is correct
77 Correct 51 ms 17448 KB Output is correct
78 Correct 98 ms 28340 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Incorrect 39 ms 13524 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 5 ms 8024 KB Output is correct
2 Correct 4 ms 7768 KB Output is correct
3 Correct 4 ms 7812 KB Output is correct
4 Correct 4 ms 7784 KB Output is correct
5 Correct 4 ms 7772 KB Output is correct
6 Correct 5 ms 7772 KB Output is correct
7 Correct 4 ms 7772 KB Output is correct
8 Correct 4 ms 7728 KB Output is correct
9 Correct 3 ms 7200 KB Output is correct
10 Correct 4 ms 7772 KB Output is correct
11 Correct 3 ms 7260 KB Output is correct
12 Correct 3 ms 7516 KB Output is correct
13 Correct 4 ms 7648 KB Output is correct
14 Correct 4 ms 8028 KB Output is correct
15 Correct 4 ms 7516 KB Output is correct
16 Correct 3 ms 7648 KB Output is correct
17 Correct 4 ms 7728 KB Output is correct
18 Correct 3 ms 7260 KB Output is correct
19 Correct 3 ms 7772 KB Output is correct
20 Correct 4 ms 7772 KB Output is correct
21 Correct 2 ms 7260 KB Output is correct
22 Correct 3 ms 7768 KB Output is correct
23 Correct 4 ms 7768 KB Output is correct
24 Correct 4 ms 7516 KB Output is correct
25 Correct 5 ms 7516 KB Output is correct
26 Correct 4 ms 7764 KB Output is correct
27 Correct 4 ms 7772 KB Output is correct
28 Correct 4 ms 7772 KB Output is correct
29 Correct 47 ms 27112 KB Output is correct
30 Correct 54 ms 25524 KB Output is correct
31 Correct 56 ms 26096 KB Output is correct
32 Correct 49 ms 25792 KB Output is correct
33 Correct 44 ms 17644 KB Output is correct
34 Correct 44 ms 16504 KB Output is correct
35 Correct 48 ms 25276 KB Output is correct
36 Correct 45 ms 24792 KB Output is correct
37 Correct 15 ms 7768 KB Output is correct
38 Correct 58 ms 25768 KB Output is correct
39 Correct 14 ms 7768 KB Output is correct
40 Correct 25 ms 8908 KB Output is correct
41 Correct 53 ms 26772 KB Output is correct
42 Correct 57 ms 26800 KB Output is correct
43 Correct 12 ms 8028 KB Output is correct
44 Correct 49 ms 25280 KB Output is correct
45 Correct 57 ms 25012 KB Output is correct
46 Correct 20 ms 8408 KB Output is correct
47 Correct 53 ms 26808 KB Output is correct
48 Correct 47 ms 25564 KB Output is correct
49 Correct 13 ms 8028 KB Output is correct
50 Correct 50 ms 17136 KB Output is correct
51 Correct 52 ms 26168 KB Output is correct
52 Correct 14 ms 7772 KB Output is correct
53 Correct 14 ms 7772 KB Output is correct
54 Correct 41 ms 17588 KB Output is correct
55 Correct 41 ms 18368 KB Output is correct
56 Correct 163 ms 32044 KB Output is correct
57 Correct 131 ms 30780 KB Output is correct
58 Correct 159 ms 32100 KB Output is correct
59 Correct 139 ms 31124 KB Output is correct
60 Correct 144 ms 24124 KB Output is correct
61 Correct 155 ms 31668 KB Output is correct
62 Correct 154 ms 28880 KB Output is correct
63 Correct 103 ms 27664 KB Output is correct
64 Correct 60 ms 10952 KB Output is correct
65 Correct 146 ms 30304 KB Output is correct
66 Correct 58 ms 11268 KB Output is correct
67 Correct 46 ms 11272 KB Output is correct
68 Correct 68 ms 27260 KB Output is correct
69 Correct 165 ms 32312 KB Output is correct
70 Correct 20 ms 8028 KB Output is correct
71 Correct 80 ms 27564 KB Output is correct
72 Correct 122 ms 29656 KB Output is correct
73 Correct 12 ms 8024 KB Output is correct
74 Correct 57 ms 18376 KB Output is correct
75 Correct 158 ms 33844 KB Output is correct
76 Correct 12 ms 7780 KB Output is correct
77 Correct 51 ms 17448 KB Output is correct
78 Correct 98 ms 28340 KB Output is correct
79 Incorrect 39 ms 13524 KB Output isn't correct
80 Halted 0 ms 0 KB -