#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,id;
bool operator < (const node &rhs)const{
if(v != rhs.v)return v > rhs.v;
return tim > rhs.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(),val[i].id = i;
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),val[i].id};
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),val[i].id};
if(sb.r >= beg)ans[tot] = seg{1,m,val[i].id},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(ans[i].v);
for(int i = 1;i <= m;i++)
if(vec[i].size() > 6)return -1;
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;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Failed |
8 ms |
12032 KB |
the answer doesn't match with the value Z |
2 |
Failed |
10 ms |
12288 KB |
the answer doesn't match with the value Z |
3 |
Failed |
135 ms |
35864 KB |
the answer doesn't match with the value Z |
4 |
Failed |
9 ms |
12160 KB |
the answer doesn't match with the value Z |
5 |
Failed |
58 ms |
21624 KB |
the answer doesn't match with the value Z |
6 |
Failed |
9 ms |
12160 KB |
the answer doesn't match with the value Z |
7 |
Failed |
10 ms |
12288 KB |
the answer doesn't match with the value Z |
8 |
Failed |
42 ms |
15992 KB |
the answer doesn't match with the value Z |
9 |
Failed |
245 ms |
41720 KB |
the answer doesn't match with the value Z |
10 |
Failed |
246 ms |
41848 KB |
the answer doesn't match with the value Z |