#include<bits/stdc++.h>
#define mp make_pair
#define pb push_back
#define ii pair<int,int>
#define all(x) (x).begin(),(x).end()
#define INF 100000000000000000
#define modulo 1000000007
#define mod 998244353
#define int long long int
using namespace std;
struct Player{
int Q,I,id;
bool operator<(Player& A){
return Q<A.Q;
}
Player(int a=0,int b=0,int c=0){
Q=a,I=b,id=c;
}
};
vector<Player> arr(1);
vector<int> A;
bool cmp(int a,int b){
return arr[a].Q<arr[b].Q;
}
int32_t main(){
ios_base::sync_with_stdio(false);
cin.tie(NULL);
// freopen("q.gir","r",stdin);
// freopen("q.cik","w",stdout);
int m,n;
cin>>m>>n;
for(int i=0;i<n;i++){
int a,b;
cin>>a>>b;
arr.pb(Player(a,b,i+1));
A.pb(i+1);
}
sort(all(A),cmp);
reverse(all(A));
vector<int> matrix[6];
int ind=0,cnt=0;
for(int i=0;i<6;i++){
matrix[i].resize(m);
for(int j=0;j<m;j++){
arr[A[ind]].I--;
matrix[i][j]=A[ind];
if(arr[A[ind]].I==0)ind++;
}
}
for(int i=0;i<6;i++){
for(int j=0;j<m;j++)cnt+=arr[matrix[i][j]].Q;
}
cout<<cnt<<"\n";
for(int i=0;i<6;i++)cout<<matrix[i][0]<<" ";
cout<<"\n";
vector<pair<int,ii> >ans;
for(int i=1;i<m;i++){
vector<int>L,R;
for(int j=0;j<6;j++){
ind=0;
while(ind<6){
if(matrix[ind][i]==matrix[j][i-1])break;
ind++;
}
if(ind==6)L.pb(matrix[j][i-1]);
}
for(int j=0;j<6;j++){
ind=0;
while(ind<6){
if(matrix[ind][i-1]==matrix[j][i])break;
ind++;
}
if(ind==6)R.pb(matrix[j][i]);
}
for(int j=0;j<L.size();j++){
ans.pb({i,{L[j],R[j]}});
}
}
cout<<ans.size()<<"\n";
for(int i=0;i<ans.size();i++)cout<<ans[i].first<<" "<<ans[i].second.first<<" "<<ans[i].second.second<<"\n";
}
Compilation message
hokej.cpp: In function 'int32_t main()':
hokej.cpp:75:26: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
for(int j=0;j<L.size();j++){
~^~~~~~~~~
hokej.cpp:80:20: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
for(int i=0;i<ans.size();i++)cout<<ans[i].first<<" "<<ans[i].second.first<<" "<<ans[i].second.second<<"\n";
~^~~~~~~~~~~
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
376 KB |
Output is correct |
2 |
Correct |
5 ms |
760 KB |
Output is correct |
3 |
Correct |
90 ms |
25136 KB |
Output is correct |
4 |
Correct |
3 ms |
504 KB |
Output is correct |
5 |
Correct |
37 ms |
10264 KB |
Output is correct |
6 |
Correct |
3 ms |
632 KB |
Output is correct |
7 |
Correct |
6 ms |
1016 KB |
Output is correct |
8 |
Correct |
49 ms |
7076 KB |
Output is correct |
9 |
Correct |
346 ms |
40432 KB |
Output is correct |
10 |
Correct |
325 ms |
40456 KB |
Output is correct |