# |
Submission time |
Handle |
Problem |
Language |
Result |
Execution time |
Memory |
639052 |
2022-09-08T11:43:35 Z |
inksamurai |
Hokej (COCI17_hokej) |
C++17 |
|
132 ms |
24360 KB |
#include <bits/stdc++.h>
#define int ll
using namespace std;
#define rep(i,n) for(int i=0;i<n;i++)
#define rng(i,c,n) for(int i=c;i<n;i++)
#define per(i,n) for(int i=n-1;i>=0;i--)
#define fi first
#define se second
#define pb push_back
#define sz(a) (int)a.size()
#define vec(...) vector<__VA_ARGS__>
#define _3RhsN1z ios::sync_with_stdio(0),cin.tie(0)
typedef long long ll;
using pii=pair<int,int>;
using vi=vector<int>;
void print(){cout<<'\n';}
template<class h,class...t>
void print(const h&v,const t&...u){cout<<v<<' ',print(u...);}
// e
// i love constructiveeeeeeeeeeeeeesssssssssssssssssss !!!!!!!!
signed main(){
_3RhsN1z;
int m,n;
cin>>m>>n;
using T=pair<int,pii>;
vec(T) a(n);
vec(pii) ina(n);
rep(i,n){
cin>>a[i].fi>>a[i].se.fi;
a[i].se.se=i;
ina[i]={a[i].fi,a[i].se.fi};
}
sort(a.begin(),a.end());
const int si=6;
int k=0;
vec(vec(pii)) rbts(si);
vi qs(n);
while(k<si){
int now=0;
while(now<m){
assert(sz(a));
T u=a.back();
a.pop_back();
int need=min(u.se.fi,m-now);
assert(need>0);
qs[u.se.se]+=need;
rbts[k].pb({need,u.se.se});
u.se.fi-=need;
now+=need;
if(u.se.fi>0){
a.pb(u);
}
}
k+=1;
}
while(1){
bool fnd=0;
rep(i,si){
if(sz(rbts[i])>1){
pii p=rbts[i].back();
if(qs[p.se]==m){
fnd=1;
int ni=i+1;
vec(pii) tmp=rbts[ni];
rbts[i].pop_back();
rng(j,1,sz(tmp)){
rbts[i].pb(tmp[j]);
}
rbts.erase(rbts.begin()+ni);
tmp.clear();
tmp.pb({m,p.se});
rbts.pb(tmp);
}
}
}
if(!fnd) break;
}
int res=0;
rep(i,si){
for(auto p:rbts[i]){
res+=p.fi*ina[p.se].fi;
}
}
cout<<res<<"\n";
rep(i,si){
cout<<rbts[i][0].se+1<<" ";
}
cout<<"\n";
vec(T) pns;
rep(i,si){
int tm=0;
rep(j,sz(rbts[i])-1){
tm+=rbts[i][j].fi;
pns.pb({tm,{rbts[i][j].se,rbts[i][j+1].se}});
}
}
sort(pns.begin(),pns.end());
cout<<sz(pns)<<"\n";
for(auto tp:pns){
cout<<tp.fi<<" "<<tp.se.fi+1<<" "<<tp.se.se+1<<"\n";
}
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
212 KB |
Output is correct |
2 |
Correct |
2 ms |
596 KB |
Output is correct |
3 |
Correct |
7 ms |
1492 KB |
Output is correct |
4 |
Correct |
1 ms |
340 KB |
Output is correct |
5 |
Correct |
3 ms |
852 KB |
Output is correct |
6 |
Correct |
1 ms |
468 KB |
Output is correct |
7 |
Correct |
3 ms |
724 KB |
Output is correct |
8 |
Correct |
24 ms |
5508 KB |
Output is correct |
9 |
Correct |
132 ms |
24252 KB |
Output is correct |
10 |
Correct |
125 ms |
24360 KB |
Output is correct |