답안 #168459

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
168459 2019-12-13T07:23:39 Z achibasadzishvili Gift (IZhO18_nicegift) C++14
0 / 100
68 ms 19996 KB
#include <bits/stdc++.h>
#define ll int
#define f first
#define s second
#define pb push_back
#define mp make_pair
using namespace std;
ll n,k,a[200005],s;
set<pair<ll,ll> >st;
vector<vector<ll> >ans;
vector<ll>g;
int main(){
    ios::sync_with_stdio(false);
    cin >> n >> k;

    for(int i=1; i<=n; i++){
        cin >> a[i];
        s += a[i];
        st.insert(mp(-a[i] , i));
    }

    if(s % k){
        cout << "-1";
        return 0;
    }

    ll raod = s / k;
    while(raod--){
        if((int)st.size() < k){
            cout << "-1";
            return 0;
        }
        ll p = 0;
        g.clear();
        for(set<pair<ll,ll> >::iterator it = st.begin(); it != st.end(); it++){
            p++;
            if(p > k)break;
            g.pb((*it).s);
        }
        for(int i=0; i<g.size(); i++){
            st.erase(mp(-a[g[i]] , g[i]));
            a[g[i]]--;
            if(a[g[i]])st.insert(mp(-a[g[i]] , g[i]));
        }
        ans.pb(g);
    }

    cout << (int)ans.size() << endl;

    for(int i=0; i<ans.size(); i++){
        for(int j=0; j<ans[i].size(); j++)
            cout << ans[i][j] << " ";
        cout << '\n';
    }



    return 0;
}

Compilation message

nicegift.cpp: In function 'int main()':
nicegift.cpp:40:23: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
         for(int i=0; i<g.size(); i++){
                      ~^~~~~~~~~
nicegift.cpp:50:19: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
     for(int i=0; i<ans.size(); i++){
                  ~^~~~~~~~~~~
nicegift.cpp:51:23: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
         for(int j=0; j<ans[i].size(); j++)
                      ~^~~~~~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Incorrect 2 ms 504 KB Taken too much stones from the heap
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 2 ms 504 KB Taken too much stones from the heap
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 2 ms 504 KB Taken too much stones from the heap
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Runtime error 68 ms 19996 KB Execution killed with signal 11 (could be triggered by violating memory limits)
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 2 ms 504 KB Taken too much stones from the heap
2 Halted 0 ms 0 KB -