Submission #281767

# Submission time Handle Problem Language Result Execution time Memory
281767 2020-08-23T12:53:30 Z Revo7 Hokej (COCI17_hokej) C++14
120 / 120
254 ms 38584 KB
#include <bits/stdc++.h>
#define ll long long
#define pb push_back
#define left 2*i+1
#define righ 2*i+2
#define mid (l+r)/2
#define IOS ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);

using namespace std;
const ll maxn=5e5+100;
const ll mod=1e9+9;
const ll base=27;

ll n,m;
struct player{
    ll val,cnt,id;
};
vector<player>a;
bool com(player a,player b){
    if(a.val==b.val){
        if(a.cnt==b.cnt)return a.id>b.id;
        return a.cnt<b.cnt;
    }
    return a.val<b.val;
}

ll pl[6][maxn];
struct sub{
    ll tim,x,y;
};

bool cmp(sub a,sub b){
    return a.tim<b.tim;
}
vector<sub>s;
bool flag[maxn],sw[6][maxn];
int in[maxn];
int main()
{
    //setIO("threesum");
    IOS
    cin>>m>>n;
    a.resize(n);
    for(ll i=0;i<n;i++){
        cin>>a[i].val>>a[i].cnt;
        a[i].id=i+1;
        if(a[i].cnt==m)flag[a[i].id]=1;
    }

    sort(a.begin(),a.end(),com);
    ll tot=0;
    for(int i=1;i<=n;i++)in[i]=6;
    for(int i=0;i<6&&a.size();i++){
        for(int j=0;j<m;j++){
            if(!a.size())break;
            int x=a.size()-1;
            tot+=a[x].val;
            in[a[x].id]=min(in[a[x].id],i);
            if(flag[a[x].id]&&i==in[a[x].id]+1)sw[i][j]=1;
            a[x].cnt--;
            if(!a[x].cnt)a.pop_back();
            pl[i][j]=a[x].id;
        }
    }

    cout<<tot<<endl;
    for(int i=0;i<6;i++){
        cout<<pl[i][0]<<' ';
    }
    cout<<endl;

    for(int i=0;i<6;i++){
        for(int j=0;j<m;j++){
            if(sw[i][j])swap(pl[i][j],pl[i-1][j]);
        }
    }
    for(int i=0;i<6;i++){
        for(int j=1;j<m;j++){
            if(pl[i][j]!=pl[i][j-1]&&pl[i][j]>0){
                s.pb({j,pl[i][j-1],pl[i][j]});
            }
        }
    }
    sort(s.begin(),s.end(),cmp);
    cout<<s.size()<<endl;
    for(auto it:s)cout<<it.tim<<' '<<it.x<<' '<<it.y<<endl;
    return 0;
}


# Verdict Execution time Memory Grader output
1 Correct 1 ms 384 KB Output is correct
2 Correct 3 ms 768 KB Output is correct
3 Correct 37 ms 24568 KB Output is correct
4 Correct 1 ms 512 KB Output is correct
5 Correct 19 ms 10112 KB Output is correct
6 Correct 4 ms 640 KB Output is correct
7 Correct 4 ms 768 KB Output is correct
8 Correct 56 ms 6072 KB Output is correct
9 Correct 241 ms 38584 KB Output is correct
10 Correct 254 ms 38584 KB Output is correct