# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
141369 | SeekingOblivion | Hokej (COCI17_hokej) | C++14 | 507 ms | 6628 KiB |
This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#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 |
---|---|---|---|---|
Fetching results... |