Submission #84901

# Submission time Handle Problem Language Result Execution time Memory
84901 2018-11-17T18:28:45 Z ToadDaveski Gift (IZhO18_nicegift) C++14
0 / 100
663 ms 45660 KB
#include <bits/stdc++.h>
#define ll long long
#define fr first
#define sc second
using namespace std;
vector <vector <pair <ll,ll> >  > q;
ll a[2000001];
map <ll,ll> poz;
vector <ll> ans;
int main()
{
    ll n,k,i,j,ma=0;
    cin>>n>>k;
    ll sum=0,part;
    for(i=1;i<=n;i++)
    {
        cin>>a[i];
        sum+=a[i];
        ma=max(ma,a[i]);
    }
    part=sum/k;
    if (sum%k || part<ma )
    {
        cout<<-1;
        return 0;
    }
    sum=0;
    vector <pair <ll,ll> > temp;
    for(i=1;i<=n;i++)
    {
        sum+=a[i];
        if (sum>=part)
        {
            temp.push_back({a[i]-(sum-part),i});
            q.push_back(temp);
            temp.clear();
            sum=sum-part;
            if (sum) temp.push_back({sum,i});
        }
        else
        {
            temp.push_back({a[i],i});
        }
    }
    while(true)
    {
        ll mi=1e9;
        for(i=0;i<k;i++)
            mi=min(mi,q[i][poz[i]].fr);
        ans.push_back(mi);
        ll kol=0;
        for(i=0;i<k;i++)
        {
            ans.push_back(q[i][poz[i]].sc);
            q[i][poz[i]].fr-=mi;
            if (poz[i]<q[i].size() && !q[i][poz[i]].fr)
            {
                poz[i]++;
                if (poz[i]<q[i].size()) kol++;
            }
        }
        if (!kol)
            break;
    }
    ll toad=0;
    while(toad<ans.size())
    {
        cout<<ans[toad]<<" ";
        if (((toad+1)%(k+1))==0)
            cout<<endl;
        toad++;
    }
    return 0;
}

Compilation message

nicegift.cpp: In function 'int main()':
nicegift.cpp:56:23: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
             if (poz[i]<q[i].size() && !q[i][poz[i]].fr)
nicegift.cpp:59:27: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
                 if (poz[i]<q[i].size()) kol++;
nicegift.cpp:66:15: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
     while(toad<ans.size())
           ~~~~^~~~~~~~~~~
nicegift.cpp:12:14: warning: unused variable 'j' [-Wunused-variable]
     ll n,k,i,j,ma=0;
              ^
# Verdict Execution time Memory Grader output
1 Incorrect 2 ms 256 KB Not all heaps are empty in the end
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 2 ms 256 KB Not all heaps are empty in the end
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 2 ms 256 KB Not all heaps are empty in the end
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 663 ms 45660 KB Participant has too long output
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 2 ms 256 KB Not all heaps are empty in the end
2 Halted 0 ms 0 KB -