#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 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+=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 |
380 KB |
Output is correct |
2 |
Correct |
8 ms |
504 KB |
Output is correct |
3 |
Failed |
30 ms |
888 KB |
the answer doesn't match with the value Z |
4 |
Correct |
2 ms |
380 KB |
Output is correct |
5 |
Correct |
11 ms |
636 KB |
Output is correct |
6 |
Correct |
5 ms |
376 KB |
Output is correct |
7 |
Incorrect |
10 ms |
504 KB |
Output isn't correct |
8 |
Incorrect |
90 ms |
1912 KB |
Output isn't correct |
9 |
Incorrect |
502 ms |
6648 KB |
Output isn't correct |
10 |
Incorrect |
502 ms |
6724 KB |
Output isn't correct |