이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include<bits/stdc++.h>
using namespace std;
#define ll long long int
ll t,n,m,k,cnt;
ll a[100+1],b[100+1],c[100+1];
void anomalous_solve()
{
cin>>n>>k;
pair<ll,ll>p[n+1];
for(int i=1;i<=n;i++)
{
cin>>p[i].first;
p[i].second=i;
}
sort(p+1,p+1+n);
ll pos=1,cnt=1;
ll l=1,r=n;
while(r>=l)
{
if(p[r].first>=p[l].first)
{
c[pos]=min(p[l].first,p[r].first);
a[pos]=p[l].second;
b[pos]=p[r].second;
p[r].first-=p[l].first;
p[l].first=0;
l++;
if(p[r].first==0)
{
r--;
}
}
else
{
c[pos]=min(p[l].first,p[r].first);
a[pos]=p[l].second;
b[pos]=p[r].second;
p[l].first-=p[r].first;
p[r].first=0;
r--;
if(p[l].first==0)
{
l++;
}
}
t=(r-l)+1;
if(t==1)
{
cout<<"-1";return;
}
sort(p+1,p+1+n);
r=n;l=n-t+1;
cnt++;
pos++;
}
cnt--;
cout<<cnt<<"\n";
for(int i=1;i<=cnt;i++)
{
cout<<c[i]<<" "<<a[i]<<" "<<b[i]<<"\n";
}
}
int main()
{
// freopen("INPUT.txt","r",stdin);
// freopen("OUTPUT.txt","w",stdout);
ios_base::sync_with_stdio();
cin.tie(NULL);
cout.tie(NULL);
ll test=1;
//cin>>test;
for(int pos=1;pos<=test;pos++)
anomalous_solve();
}
# | 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... |