Codeforces Round #772 (Div. 2) C. Differential Sorting

思路
逆推,如果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);
#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()
{
    // debug;
    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);
        }
    }
    
}

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值