#include<iostream>
#include<fstream>
#define fin cin
#define fout cout
#define f first
#define sf second.first
#define ss second.second
#include<algorithm>
using namespace std;
//ifstream fin("date.in");
//ofstream fout("date.out");
int m,n,i,l,p,start[6],mov,nr;
pair<int,pair<int,int> > v[500001],sol[1500001];
long long val;
int main(){
fin>>m>>n;
for(i=1;i<=n;i++){
fin>>v[i].f>>v[i].sf;
v[i].sf=min(v[i].sf,m);
v[i].ss=i;
}
sort(v+1,v+n+1);
l=0;p=0;
for(i=n;i>=1;i--)
{
while(v[i].sf&&l<6)
{
if(p==0) start[l]=v[i].ss;
else
{
if(v[i].sf==m&&l!=5)
{
val+=1LL*m*v[i].f;
start[++l]=v[i].ss;
v[i]=v[i-1];
break;
}
sol[++nr].f=p-1,sol[nr].sf=v[i+1].ss,sol[nr].ss=v[i].ss;
}
if(p+v[i].sf-1>=m)
mov=m-p,p=m-1;
else
mov=v[i].sf,p+=v[i].sf-1;
v[i].sf-=mov;
val+=1ll*mov*v[i].f;
p++;
if(p>=m) l++,p=0;
}
}
fout<<val<<"\n";
for(i=0;i<=5;i++) fout<<start[i]<<" ";
fout<<"\n"<<nr<<"\n";
sort(sol+1,sol+1+nr);
for(i=1;i<=nr;i++)
fout<<sol[i].f+1<<" "<<sol[i].sf<<" "<<sol[i].ss<<"\n";
return 0;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
376 KB |
Output is correct |
2 |
Correct |
8 ms |
376 KB |
Output is correct |
3 |
Correct |
30 ms |
632 KB |
Output is correct |
4 |
Correct |
2 ms |
376 KB |
Output is correct |
5 |
Correct |
11 ms |
504 KB |
Output is correct |
6 |
Correct |
5 ms |
376 KB |
Output is correct |
7 |
Incorrect |
9 ms |
504 KB |
Output isn't correct |
8 |
Incorrect |
93 ms |
1656 KB |
Output isn't correct |
9 |
Incorrect |
496 ms |
6684 KB |
Output isn't correct |
10 |
Incorrect |
507 ms |
6564 KB |
Output isn't correct |