#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();
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
212 KB |
n=4 |
2 |
Correct |
0 ms |
212 KB |
n=3 |
3 |
Correct |
0 ms |
212 KB |
n=3 |
4 |
Incorrect |
0 ms |
212 KB |
Jury has the answer but participant has not |
5 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
212 KB |
n=4 |
2 |
Correct |
0 ms |
212 KB |
n=3 |
3 |
Correct |
0 ms |
212 KB |
n=3 |
4 |
Incorrect |
0 ms |
212 KB |
Jury has the answer but participant has not |
5 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
212 KB |
n=4 |
2 |
Correct |
0 ms |
212 KB |
n=3 |
3 |
Correct |
0 ms |
212 KB |
n=3 |
4 |
Incorrect |
0 ms |
212 KB |
Jury has the answer but participant has not |
5 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Execution timed out |
2052 ms |
16060 KB |
Time limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
212 KB |
n=4 |
2 |
Correct |
0 ms |
212 KB |
n=3 |
3 |
Correct |
0 ms |
212 KB |
n=3 |
4 |
Incorrect |
0 ms |
212 KB |
Jury has the answer but participant has not |
5 |
Halted |
0 ms |
0 KB |
- |