D. Corrupted Array
time limit per test
2 seconds
memory limit per test
256 megabytes
input
standard input
output
standard output
You are given a number nn and an array b1,b2,…,bn+2b1,b2,…,bn+2, obtained according to the following algorithm:
For example, the array b=[2,3,7,12,2]b=[2,3,7,12,2] it could be obtained in the following ways:
For the given array bb, find any array aa that could have been guessed initially.
Input
The first line contains a single integer tt (1≤t≤1041≤t≤104). Then tt test cases follow.
The first line of each test case contains a single integer nn (1≤n≤2⋅1051≤n≤2⋅105).
The second row of each test case contains n+2n+2 integers b1,b2,…,bn+2b1,b2,…,bn+2 (1≤bi≤1091≤bi≤109).
It is guaranteed that the sum of nn over all test cases does not exceed 2⋅1052⋅105.
Output
For each test case, output:
If there are several arrays of aa, you can output any.
Example
input
Copy
4 3 2 3 7 12 2 4 9 1 7 1 6 5 5 18 2 2 3 2 9 2 3 2 6 9 2 1
output
Copy
2 3 7 -1 2 2 2 3 9 1 2 6
事先让n=n+2
枚举x的位置,取剩下n-1个数的最值,看是否等于n-2个数的和即可,排序与前缀和处理,很水的D
- #include
- #include
- #include
- #include
- #include
- #include
- #include
- #include
- #include
- #include
- using namespace std;
-
- typedef long long int ll;
-
- ll a[200000+10];
- ll sum[200000+10];
-
-
- int main()
- {
-
- int t ;
-
- cin>>t ;
-
- while(t--)
- {
- int n;
-
- cin>>n;
-
- for(int i=1;i<=n+2;i++)
- {
- cin>>a[i];
- }
-
- sort(a+1,a+1+n+2);
-
- for(int i=1;i<=n+2;i++)
- {
- sum[i]=sum[i-1]+a[i];
-
- }
-
- int flag=0;
-
- int pos;
-
-
-
- n+=2;
-
- for(int i=1;i<=n;i++)
- {
- if(i!=n)
- {
-
- ll l=sum[i-1];
-
- ll r=sum[n-1]-sum[i];
-
- if(l+r==a[n])
- {
- flag=1;
-
- pos=i;
-
- break;
- }
- }
- else
- {
- if(sum[n-2]==a[n-1])
- {
- flag=1;
-
- pos=n;
-
-
- break;
- }
- }
- }
-
- if(flag==0)
- {
- cout<<-1<
- }
- else
- {
- if(pos==n)
- {
- for(int i=1;i<=n-2;i++)
- {
- cout<" ";
- }
-
- cout<
- }
- else
- {
- for(int i=1;i
- {
- cout<" ";
- }
-
-
-
相关阅读:
Spring MVC 和 @ModelAttribute 注释
keil debug查看变量提示not in scope
Jmeter接口测试,关联接口实现步骤(token)
TCP流量控制和拥塞控制
并查集(数据结构)
不同路径数(冬季每日一题 4)
Java日志系列——日志门面,阿里日志规约,SLF4J
湖仓一体电商项目(十六):业务实现之编写写入ODS层业务代码
C和指针 第13章 高级指针话题 13.2 高级声明
使用Colossal-AI进行优化的测试笔记
-
原文地址:https://blog.csdn.net/jisuanji2606414/article/details/126180283