이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include <bits/stdc++.h>
#include<ext/pb_ds/assoc_container.hpp>
#include<ext/pb_ds/tree_policy.hpp>
#pragma GCC optimize("-O3")
#pragma GCC optimize("Ofast")
#pragma GCC optimize("unroll-loops")
#define fi first
#define se second
#define p_b push_back
#define pll pair<ll,ll>
#define pii pair<int,int>
#define m_p make_pair
#define all(x) x.begin(),x.end()
#define sset ordered_set
#define sqr(x) (x)*(x)
#define pw(x) (1ll << x)
using namespace std;
using namespace __gnu_pbds;
typedef long long ll;
typedef long double ld;
const ll MAXN = 1123456;
const ll N = 2e5;
mt19937_64 rnd(chrono::system_clock::now().time_since_epoch().count());
template <typename T>
using ordered_set = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;
template <typename T> void vout(T s){cout << s << endl;exit(0);}
int main(){
ios_base :: sync_with_stdio(0);
cin.tie(0);
ll n, k;
cin >> n >> k;
vector <ll> a(n);
set <pll> st;
ll sc = 0, mx = 0;
for(int i = 0; i < n; i++){
cin >> a[i];
st.insert({a[i], i});
sc += a[i];
mx = max(mx, a[i]);
}
if(sc % k)vout(-1);
if(sc < mx)vout(-1);
// pll fufel = *--st.end();
// st.erase(--st.end());
// sc -= mx;
vector < pair<ll, vector <ll> > > ans;
while(1){
vector <pll> V;
if(st.empty())break;
ll Mx = (--st.end()) -> fi;
if(sc - Mx == Mx)break;
if(sc - Mx < Mx)vout(-1);
for(int i = 0; i < k; i++){
if(st.empty())vout(-1);
pll xe = *--st.end();
V.p_b(xe);
st.erase(--st.end());
}
sc -= k;
vector <ll> c;
for(auto i : V)c.p_b(i.se);
ans.p_b({1, c});
for(auto i : V){
if(i.fi > 1)st.insert({i.fi - 1, i.se});
}
c.clear();
V.clear();
}
if(!st.empty()){
pll fufel = *--st.end();
st.erase(--st.end());
while(!st.empty()){
vector <pll> V;
for(int i = 1; i < k; i++){
if(st.empty())vout(-1);
pll xe = *--st.end();
V.p_b(xe);
st.erase(--st.end());
}
sc -= k;
vector <ll> c;
for(auto i : V)c.p_b(i.se);
c.p_b(fufel.se);
ans.p_b({1, c});
for(auto i : V){
if(i.fi > 1)st.insert({i.fi - 1, i.se});
}
c.clear();
V.clear();
}
}
cout << ans.size() << "\n";
for(auto i : ans){
cout << i.fi;
for(auto j : i.se)cout << " " << j + 1;
cout << "\n";
}
return 0;
}
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |