#include<bits/stdc++.h>
#include "tickets.h"
using namespace std;
int k,n,m,n2;
vector<vector<int>>answer;
vector<vector<pair<int,int>>>Tab;
int miejsce[1509];
vector<int>V1[1509],V2[1509];
int CzyWziete[1509];
long long find_maximum(int K, vector<vector<int>>A)
{
k=K;
n = A.size();
n2=n/2;
m = A[0].size();
answer.resize(n,vector<int>(m,-1));
for(int i=0;i<n;i++)
{
vector<pair<int,int>>Temp;
for(int j=0;j<m;j++)
{
Temp.push_back({A[i][j],j});
}
sort(Temp.begin(),Temp.end());
Tab.push_back(Temp);
}
long long wynik=0;
const int kij=m-k;
for(int i=0;i<n;i++)
{
for(int j=kij;j<m;j++)
{
wynik+=Tab[i][j].first;
}
}
set<pair<int,int>>S;
for(int i=0;i<n;i++)
{
miejsce[i]=0;
S.insert({Tab[i][0].first+Tab[i][kij].first,i});
}
for(int I=1;I<=n*k/2;I++)
{
pair<int,int>xd=*S.begin();
S.erase(xd);
wynik-=xd.first;
miejsce[xd.second]++;
if(miejsce[xd.second]+kij<m)
{
S.insert({Tab[xd.second][miejsce[xd.second]].first+Tab[xd.second][miejsce[xd.second]+kij].first,xd.second});
}
}
for(int i=0;i<n;i++)
{
for(int j=0;j<miejsce[i];j++)
{
V1[i].push_back(Tab[i][j].second);
}
for(int j=miejsce[i]+kij;j<m;j++)
{
V2[i].push_back(Tab[i][j].second);
}
}
memset(CzyWziete,-1,sizeof(CzyWziete));
for(int i=0;i<k;i++)
{
int IleMalych=n2;
for(int j=0;j<n;j++)
{
if((int)V1[j].size()==0)
{
answer[j][V2[j].back()]=i;
V2[j].pop_back();
CzyWziete[j]=i;
}
else if((int)V2[j].size()==0)
{
answer[j][V1[j].back()]=i;
V1[j].pop_back();
CzyWziete[j]=i;
IleMalych--;
}
}
for(int j=0;j<n;j++)
{
if(CzyWziete[j]==i){continue;}
if(IleMalych>0)
{
answer[j][V1[j].back()]=i;
V1[j].pop_back();
IleMalych--;
}
else
{
answer[j][V2[j].back()]=i;
V2[j].pop_back();
}
}
}
allocate_tickets(answer);
return wynik;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
348 KB |
Output is correct |
2 |
Correct |
0 ms |
516 KB |
Output is correct |
3 |
Correct |
1 ms |
348 KB |
Output is correct |
4 |
Correct |
0 ms |
348 KB |
Output is correct |
5 |
Correct |
1 ms |
604 KB |
Output is correct |
6 |
Correct |
2 ms |
860 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
512 KB |
Output is correct |
2 |
Correct |
0 ms |
348 KB |
Output is correct |
3 |
Correct |
0 ms |
520 KB |
Output is correct |
4 |
Correct |
2 ms |
856 KB |
Output is correct |
5 |
Correct |
20 ms |
4208 KB |
Output is correct |
6 |
Correct |
461 ms |
91108 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
360 KB |
Output is correct |
2 |
Correct |
1 ms |
360 KB |
Output is correct |
3 |
Correct |
0 ms |
532 KB |
Output is correct |
4 |
Correct |
2 ms |
616 KB |
Output is correct |
5 |
Correct |
19 ms |
3632 KB |
Output is correct |
6 |
Correct |
465 ms |
80736 KB |
Output is correct |
7 |
Correct |
487 ms |
84108 KB |
Output is correct |
8 |
Correct |
3 ms |
784 KB |
Output is correct |
9 |
Correct |
0 ms |
348 KB |
Output is correct |
10 |
Correct |
0 ms |
348 KB |
Output is correct |
11 |
Correct |
0 ms |
348 KB |
Output is correct |
12 |
Correct |
5 ms |
1116 KB |
Output is correct |
13 |
Correct |
27 ms |
3164 KB |
Output is correct |
14 |
Correct |
18 ms |
3216 KB |
Output is correct |
15 |
Correct |
459 ms |
85840 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
344 KB |
Output is correct |
2 |
Correct |
1 ms |
348 KB |
Output is correct |
3 |
Correct |
0 ms |
348 KB |
Output is correct |
4 |
Correct |
3 ms |
604 KB |
Output is correct |
5 |
Correct |
23 ms |
4812 KB |
Output is correct |
6 |
Correct |
3 ms |
1200 KB |
Output is correct |
7 |
Correct |
6 ms |
1432 KB |
Output is correct |
8 |
Correct |
735 ms |
105788 KB |
Output is correct |
9 |
Correct |
672 ms |
99684 KB |
Output is correct |
10 |
Correct |
720 ms |
99028 KB |
Output is correct |
11 |
Correct |
634 ms |
105972 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
348 KB |
Output is correct |
2 |
Correct |
3 ms |
604 KB |
Output is correct |
3 |
Correct |
2 ms |
600 KB |
Output is correct |
4 |
Correct |
3 ms |
608 KB |
Output is correct |
5 |
Correct |
3 ms |
600 KB |
Output is correct |
6 |
Correct |
2 ms |
604 KB |
Output is correct |
7 |
Correct |
1 ms |
348 KB |
Output is correct |
8 |
Correct |
0 ms |
348 KB |
Output is correct |
9 |
Correct |
2 ms |
604 KB |
Output is correct |
10 |
Correct |
2 ms |
600 KB |
Output is correct |
11 |
Correct |
2 ms |
604 KB |
Output is correct |
12 |
Correct |
3 ms |
600 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
348 KB |
Output is correct |
2 |
Correct |
3 ms |
604 KB |
Output is correct |
3 |
Correct |
2 ms |
600 KB |
Output is correct |
4 |
Correct |
3 ms |
608 KB |
Output is correct |
5 |
Correct |
3 ms |
600 KB |
Output is correct |
6 |
Correct |
2 ms |
604 KB |
Output is correct |
7 |
Correct |
1 ms |
348 KB |
Output is correct |
8 |
Correct |
0 ms |
348 KB |
Output is correct |
9 |
Correct |
2 ms |
604 KB |
Output is correct |
10 |
Correct |
2 ms |
600 KB |
Output is correct |
11 |
Correct |
2 ms |
604 KB |
Output is correct |
12 |
Correct |
3 ms |
600 KB |
Output is correct |
13 |
Correct |
23 ms |
4140 KB |
Output is correct |
14 |
Correct |
16 ms |
4048 KB |
Output is correct |
15 |
Correct |
26 ms |
4448 KB |
Output is correct |
16 |
Correct |
27 ms |
4692 KB |
Output is correct |
17 |
Correct |
1 ms |
604 KB |
Output is correct |
18 |
Correct |
2 ms |
848 KB |
Output is correct |
19 |
Correct |
2 ms |
528 KB |
Output is correct |
20 |
Correct |
30 ms |
3884 KB |
Output is correct |
21 |
Correct |
33 ms |
4160 KB |
Output is correct |
22 |
Correct |
35 ms |
3928 KB |
Output is correct |
23 |
Correct |
30 ms |
4460 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
348 KB |
Output is correct |
2 |
Correct |
0 ms |
516 KB |
Output is correct |
3 |
Correct |
1 ms |
348 KB |
Output is correct |
4 |
Correct |
0 ms |
348 KB |
Output is correct |
5 |
Correct |
1 ms |
604 KB |
Output is correct |
6 |
Correct |
2 ms |
860 KB |
Output is correct |
7 |
Correct |
1 ms |
512 KB |
Output is correct |
8 |
Correct |
0 ms |
348 KB |
Output is correct |
9 |
Correct |
0 ms |
520 KB |
Output is correct |
10 |
Correct |
2 ms |
856 KB |
Output is correct |
11 |
Correct |
20 ms |
4208 KB |
Output is correct |
12 |
Correct |
461 ms |
91108 KB |
Output is correct |
13 |
Correct |
1 ms |
360 KB |
Output is correct |
14 |
Correct |
1 ms |
360 KB |
Output is correct |
15 |
Correct |
0 ms |
532 KB |
Output is correct |
16 |
Correct |
2 ms |
616 KB |
Output is correct |
17 |
Correct |
19 ms |
3632 KB |
Output is correct |
18 |
Correct |
465 ms |
80736 KB |
Output is correct |
19 |
Correct |
487 ms |
84108 KB |
Output is correct |
20 |
Correct |
3 ms |
784 KB |
Output is correct |
21 |
Correct |
0 ms |
348 KB |
Output is correct |
22 |
Correct |
0 ms |
348 KB |
Output is correct |
23 |
Correct |
0 ms |
348 KB |
Output is correct |
24 |
Correct |
5 ms |
1116 KB |
Output is correct |
25 |
Correct |
27 ms |
3164 KB |
Output is correct |
26 |
Correct |
18 ms |
3216 KB |
Output is correct |
27 |
Correct |
459 ms |
85840 KB |
Output is correct |
28 |
Correct |
1 ms |
344 KB |
Output is correct |
29 |
Correct |
1 ms |
348 KB |
Output is correct |
30 |
Correct |
0 ms |
348 KB |
Output is correct |
31 |
Correct |
3 ms |
604 KB |
Output is correct |
32 |
Correct |
23 ms |
4812 KB |
Output is correct |
33 |
Correct |
3 ms |
1200 KB |
Output is correct |
34 |
Correct |
6 ms |
1432 KB |
Output is correct |
35 |
Correct |
735 ms |
105788 KB |
Output is correct |
36 |
Correct |
672 ms |
99684 KB |
Output is correct |
37 |
Correct |
720 ms |
99028 KB |
Output is correct |
38 |
Correct |
634 ms |
105972 KB |
Output is correct |
39 |
Correct |
0 ms |
348 KB |
Output is correct |
40 |
Correct |
3 ms |
604 KB |
Output is correct |
41 |
Correct |
2 ms |
600 KB |
Output is correct |
42 |
Correct |
3 ms |
608 KB |
Output is correct |
43 |
Correct |
3 ms |
600 KB |
Output is correct |
44 |
Correct |
2 ms |
604 KB |
Output is correct |
45 |
Correct |
1 ms |
348 KB |
Output is correct |
46 |
Correct |
0 ms |
348 KB |
Output is correct |
47 |
Correct |
2 ms |
604 KB |
Output is correct |
48 |
Correct |
2 ms |
600 KB |
Output is correct |
49 |
Correct |
2 ms |
604 KB |
Output is correct |
50 |
Correct |
3 ms |
600 KB |
Output is correct |
51 |
Correct |
23 ms |
4140 KB |
Output is correct |
52 |
Correct |
16 ms |
4048 KB |
Output is correct |
53 |
Correct |
26 ms |
4448 KB |
Output is correct |
54 |
Correct |
27 ms |
4692 KB |
Output is correct |
55 |
Correct |
1 ms |
604 KB |
Output is correct |
56 |
Correct |
2 ms |
848 KB |
Output is correct |
57 |
Correct |
2 ms |
528 KB |
Output is correct |
58 |
Correct |
30 ms |
3884 KB |
Output is correct |
59 |
Correct |
33 ms |
4160 KB |
Output is correct |
60 |
Correct |
35 ms |
3928 KB |
Output is correct |
61 |
Correct |
30 ms |
4460 KB |
Output is correct |
62 |
Correct |
59 ms |
10588 KB |
Output is correct |
63 |
Correct |
59 ms |
10672 KB |
Output is correct |
64 |
Correct |
80 ms |
12144 KB |
Output is correct |
65 |
Correct |
244 ms |
43604 KB |
Output is correct |
66 |
Correct |
334 ms |
46524 KB |
Output is correct |
67 |
Correct |
6 ms |
1556 KB |
Output is correct |
68 |
Correct |
6 ms |
1116 KB |
Output is correct |
69 |
Correct |
517 ms |
91028 KB |
Output is correct |
70 |
Correct |
570 ms |
97980 KB |
Output is correct |
71 |
Correct |
675 ms |
105988 KB |
Output is correct |
72 |
Correct |
564 ms |
89688 KB |
Output is correct |
73 |
Correct |
652 ms |
102148 KB |
Output is correct |
74 |
Correct |
478 ms |
82516 KB |
Output is correct |
75 |
Correct |
638 ms |
95192 KB |
Output is correct |