#include <cstdio>
#include <cctype>
#include <algorithm>
#include <vector>
using namespace std;
const int maxn = 5e5 + 100;
typedef long long ll;
inline int read(){
int x = 0;char c = getchar();
while(!isdigit(c))c = getchar();
while(isdigit(c))x = x * 10 + c - '0',c = getchar();
return x;
}
struct node{
int v,tim;
bool operator < (const node &rhs)const{
if(v != rhs.v)return v > rhs.v;
return tim > tim;
}
}val[maxn];
struct seg{
int l,r,v;
}ans[maxn];
int m,n,tot;
ll out;
vector<int> vec[maxn];
struct mpair{int x,y,z;};
vector<mpair> tmp;
int main(){
m = read(),n = read();
for(int i = 1;i <= n;i++)val[i].v = read(),val[i].tim = read();
sort(val + 1,val + 1 + n);
ll sum = 0;
for(int i = 1;i <= n;i++){
int beg = sum % m;
seg sa = seg{beg + 1,beg + min(val[i].tim,m - beg),i};
sum += sa.r - sa.l + 1;
val[i].tim -= sa.r - sa.l + 1;
ans[++tot] = sa;
if(sum == 6 * m)break;
if(!val[i].tim)continue;
seg sb = seg{1,min(val[i].tim,m),i};
if(sb.r >= beg)ans[tot] = seg{1,m,i},sum += beg;
else ans[++tot] = sb,sum += sb.r - sb.l + 1;
if(sum == 6 * m)break;
}
for(int i = 1;i <= tot;i++)
for(int k = ans[i].l;k <= ans[i].r;k++)vec[k].push_back(i);
for(int i = 1;i <= tot;i++)out += ll(ans[i].r - ans[i].l + 1) * val[ans[i].v].v;
printf("%lld\n",out);
for(unsigned int i = 0;i < 6;i++)printf("%d ",vec[1][i]);
printf("\n");
int vis[6];
for(int i = 2;i <= m;i++){
for(int j = 0;j < 6;j++)vis[j] = 0;
for(unsigned int j = 0;j < 6;j++){
int flag = 0;
for(unsigned int k = 0;k < 6;k++)
if(vec[i - 1][j] == vec[i][k]){
flag = 1;
break;
}
if(!flag){
for(unsigned int k = 0;k < 6;k++)
if(vec[i - 1][j] != vec[i][k] && !vis[k] && find(vec[i - 1].begin(),vec[i - 1].end(),vec[i][k]) == vec[i - 1].end()){
tmp.push_back(mpair{i - 1,vec[i - 1][j],vec[i][k]});
vis[k] = 1;
break;
}
}
}
}
printf("%d\n",(int)tmp.size());
for(unsigned int i = 0;i < tmp.size();i++){
printf("%d %d %d\n",tmp[i].x,tmp[i].y,tmp[i].z);
}
return 0;
}
Compilation message
hokej.cpp: In member function 'bool node::operator<(const node&) const':
hokej.cpp:18:14: warning: self-comparison always evaluates to false [-Wtautological-compare]
18 | return tim > tim;
| ~~~ ^ ~~~
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Failed |
8 ms |
12032 KB |
some player fainted |
2 |
Failed |
10 ms |
12288 KB |
some player fainted |
3 |
Failed |
145 ms |
35832 KB |
some player fainted |
4 |
Failed |
9 ms |
12160 KB |
some player fainted |
5 |
Failed |
58 ms |
21684 KB |
some player fainted |
6 |
Failed |
9 ms |
12160 KB |
some player fainted |
7 |
Failed |
10 ms |
12288 KB |
some player fainted |
8 |
Failed |
39 ms |
15608 KB |
some player fainted |
9 |
Failed |
237 ms |
39800 KB |
some player fainted |
10 |
Failed |
233 ms |
39928 KB |
some player fainted |