C. Polycarp Recovers the Permutation

2023-12-13 16:33:49

没啥思路,看到题解,先处理最大值,发现非常的nice

// Problem: C. Polycarp Recovers the Permutation
// Contest: Codeforces - Codeforces Round 756 (Div. 3)
// URL: https://codeforces.com/problemset/problem/1611/C
// Memory Limit: 256 MB
// Time Limit: 2000 ms
// 
// Powered by CP Editor (https://cpeditor.org)

#include<bits/stdc++.h>
using namespace std;
using ll=long long;
const int N = 2e5+10;
int a[N];
void solve()
{
	int n;cin>>n;
	for(int i=1;i<=n;i++)cin>>a[i];
	if(a[1]!=n&&a[n]!=n){
		cout<<-1<<"\n";
		return;
	}
	
	for(int i=n;i>=1;--i)cout<<a[i]<<" ";
	cout<<"\n";
}

int main()
{
	ios::sync_with_stdio(0),cin.tie(0),cout.tie(0);
	int _;cin>>_;
	while(_--)solve();
	return 0;
}

文章来源:https://blog.csdn.net/m0_60921016/article/details/134823834
本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。