思路 逆推,如果a[n-1]>a[n]或者a[n]<0都不可能构造出符合题意的数组,否则从n-3开始让a[i]=a[i+1]-a[n],这样就能保证不递减 code
#include <bits/stdc++.h>
#pragma GCC optimize(2)
#define debug freopen("_in.txt", "r", stdin), freopen("_out.txt", "w", stdout);
typedef long long ll;
typedef unsigned long long ull;
using namespace std;
const ll INF = 0x3f3f3f3f3f3f3f3f;
const ll maxn = 3e5 + 10;
const ll maxm = 1e4 + 10;
const ll mod = 998244353;
const double pi = acos(-1);
const double eps = 1e-8;
ll n, m,tot, T;
ll arr[maxn],vis[35];
int main()
{
scanf("%lld", &T);
while(T--)
{
scanf("%lld", &n);
for(ll i=1;i<=n;i++)
{
scanf("%lld",&arr[i]);
}
if(arr[n-1]>arr[n])
{
printf("-1\n");
continue;
}
if(arr[n-1]<0&&arr[n]<0)
{
ll flag=1;
for(ll i=2;i<=n;i++)
{
if(arr[i]<arr[i-1])
{
flag=0;
}
}
if(flag)
{
printf("0\n");
}
else
{
printf("-1\n");
}
continue;
}
printf("%lld\n",n-2);
for(ll i=n-2;i;i--)
{
printf("%lld %lld %lld\n",i,i+1,n);
}
}
}
|