# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
516219 | fcmalkcin | Gift (IZhO18_nicegift) | C++17 | 735 ms | 113044 KiB |
This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
/*#pragma GCC optimize("Ofast")
#pragma GCC optimization("unroll-loops, no-stack-protector")
#pragma GCC target("avx,avx2,fma")*/
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define pll pair<ll,ll>
#define ff first
#define ss second
#define pb push_back
#define endl "\n"
#define F(i,a,b) for (ll i=a;i<=b;i++)
mt19937 rnd(chrono::steady_clock::now().time_since_epoch().count());
const ll maxn=1e6+40;
const ll mod=1000003 ;
const ll base=3e18;
/// you will be the best but now you just are trash
/// goal 2/7
ll a[maxn];
int main()
{
ios_base::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
if (fopen("t.inp", "r"))
{
freopen("test.inp", "r", stdin);
freopen("test.out", "w", stdout);
}
ll n, k;
cin>> n>> k;
set<pll> st;
for (int i=1;i<=n;i++)
{
cin>> a[i];
st.insert(make_pair(a[i],i));
}
vector<pair<ll,vector<ll>>> ans;
while (st.size()>=k)
{
auto it=(st.begin());
ll val=(*it).ff;
vector<ll> vt;
vt.pb((*it).ss);
it=st.end();
ll len=k-1;
vector<pll> vt1;
while (len--)
{
it--;
vt.pb((*it).ss);
vt1.pb((*it));
}
ans.pb(make_pair(val,vt));
st.erase(st.begin());
for (auto to:vt1)
{
pll p=to;
st.erase(p);
if (p.ff>val)
{
p.ff-=val;
st.insert(p);
}
}
}
if (st.size())
{
cout <<-1;
return 0;
}
cout <<ans.size()<<endl;
for (auto p:ans)
{
cout <<p.ff<<" ";
for (auto to:p.ss) cout <<to<<" ";
cout <<endl;
}
}
Compilation message (stderr)
# | 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... |