测试点#2#4#16怎么也不过去,20pts求助
查看原帖
测试点#2#4#16怎么也不过去,20pts求助
724593
Decepticon楼主2023/2/1 21:23
#include <bits/stdc++.h>
using namespace std;
int t;

int main(){
	cin >> t;
	for(int i = 1; i <= t; i++){
		long long n,a,b;
		cin >> n >> a >> b;
		long long sum = 0;
		for(int j = 1; j <= n; j++){
			sum += j;
		}
		if(sum < a+b){
			cout << "-1\n";
		} else {
			if(a == 0 && b == 0){
				for(int j = 1; j <= n; j++){
					cout << j << " ";
				}
				cout << "\n";
			} else if(a == 0){
				long long z = 0;
				for(int j = n/2+1; j <= n; j++){
					z += j;
				}
				if(z < b){
					cout << "-1\n";
				} else {
					for(int j = 1; j <= n; j++){
						cout << j << " ";
					}
					cout << "\n";
				}
			} else if(b == 0){
				long long z = 0;
				for(int j = n/2+1; j <= n; j++){
					z += j;
				}
				if(z < a){
					cout << "-1\n";
				} else {
					for(int j = n; j >= 1; j--){
						cout << j << " ";
					}
					cout << "\n";
				}
			} else {
				int x[100005] = {};
				long long c = 0,d = 0;
				for(int j = 1; j <= n; j++){
					x[j] = j;
					if(j <= n/2) c += j;
					else d += j;
				}
				if(c <= a){
					if(d < b){
						cout << "-1\n";
					} else {
						if(a-c > d-b){
							cout << "-1\n";
						} else {
							int s[100005] = {},cnt = 1;
							long long e = a-c,f = a-c;
							for(int j = n-1; j >= 1; j -= 2){
								if(e >= j){
									e -= j;
									s[cnt] = j;
									cnt += 1;
								} 
							}
							if(e != 0){
								int r[100005] = {},q = 1;
								for(int j = 1; j <= n-1; j += 2){
									if(f >= j){
									   r[q] = j;
									   q += 1;
									   f -= j;
								    }
								}
								if(f != 0){
									cout << "-1\n";
								} else {
									for(int j = 1; j < q; j++){
										swap(x[(1+n-r[j])/2],x[(1+n+r[j])/2]);
									}
									for(int j = 1; j <= n; j++){
										cout << x[j] << " ";
									}
									cout << "\n";
								}
							} else {
								for(int j = 1; j < cnt; j++){
									swap(x[(1+n-s[j])/2],x[(1+n+s[j])/2]);
								}
								for(int j = 1; j <= n; j++){
									cout << x[j] << " ";
								}
								cout << "\n";
							}
						}
					}
				} else {
					if(d < b){
						cout << "-1\n";
					} else {
						for(int j = 1; j <= n; j++){
							cout << j << " ";
						}
						cout << "\n";
				    }
				}
			}
		}
	}
	return 0;
}
2023/2/1 21:23
加载中...