#include<queue>
#include<map>
#include <string>
#include<bits/stdc++.h>
#define pi 3.141592654
#define forr(i,a,b) for(int i=a;i<=b;i++)
#define F first
#define S second
#define input ios_base::sync_with_stdio(0);cin.tie(0);
//#define x real()
//#define y imag()
using namespace std;
typedef pair<double,double>pdd;
typedef long long ll;
typedef pair<ll, ll>pii;
//typedef complex<double> point;
//template<typename T>T gcd(T x, T y) { if(y == 0)return x; else return gcd(y, x%y); }
//typedef bitset<30> mask;
//int x[8]={1,0,0,-1,-1,-1,1,1};
//int y[8]={0,1,-1,0,-1,1,-1,1};
//#define var(x) ((x)<<1)
//#define nvar(x) ((x)^1)
const int N=100000,M=100000;
int m,n,b[8][600000];
pair<pair<int,int>,int>a[600000];
ll sum;
main()
{
//cout<<Pow((ll)1000000,(ll)110);
//freopen("input.txt","r",stdin);
//freopen("output.txt","w",stdout);
// char input[15];
// scanf("%s", &input); array of char
// gets(c+1); array of char
//printf("%s, ",name[k[i]].c_str()); printf of string
//priority_queue<ll,vector<ll>,greater<ll>>y;
input;
cin>>m>>n;
forr(i,1,n)
cin>>a[i].F.F>>a[i].F.S,a[i].S=i;
sort(a+1,a+1+n);
reverse(a+1,a+1+n);
int idx=1,c=a[idx].F.S;
forr(i,1,6)
{
forr(j,1,m)
{
if(c)
{
b[i][j]=a[idx].S;
sum+=(ll)a[idx].F.F;
c--;
}
else
{
idx++;
c=a[idx].F.S;
b[i][j]=a[idx].S;
sum+=(ll)a[idx].F.F;
c--;
}
}
}
vector<pair<int,pair<int,int>>>ans;
forr(j,2,m)
{
int s=0;
forr(i,1,6)
{
if(b[i][j]!=b[i][j-1])
{
if(s==0)s=i;
if(b[i][j]==b[i+1][j-1])continue;
ans.push_back({j-1,{b[s][j-1],b[i][j]}});
s=0;
}
}
}
sort(ans.begin(),ans.end());
cout<<sum<<endl;
forr(i,1,6)cout<<b[i][1]<<" ";
cout<<endl<<(int)ans.size()<<endl;
for(auto p:ans)cout<<p.F<<" "<<p.S.F<<" "<<p.S.S<<endl;
/*
forr(j,1,m)
{
forr(i,1,6)cout<<b[i][j]<<" ";
cout<<endl;
}
*/
return 0;
}
Compilation message
hokej.cpp:29:7: warning: ISO C++ forbids declaration of 'main' with no type [-Wreturn-type]
main()
^
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
384 KB |
Output is correct |
2 |
Correct |
4 ms |
512 KB |
Output is correct |
3 |
Correct |
25 ms |
12536 KB |
Output is correct |
4 |
Correct |
2 ms |
384 KB |
Output is correct |
5 |
Correct |
13 ms |
5376 KB |
Output is correct |
6 |
Correct |
4 ms |
512 KB |
Output is correct |
7 |
Correct |
4 ms |
512 KB |
Output is correct |
8 |
Correct |
37 ms |
3192 KB |
Output is correct |
9 |
Correct |
157 ms |
18472 KB |
Output is correct |
10 |
Correct |
163 ms |
18408 KB |
Output is correct |