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<" ";
- }
-
-
-
相关阅读:
国内做SRM系统的公司哪家比较好?如何利用SRM系统管理好供应商?
WPF中行为与触发器的概念及用法
什么是Transformer架构的自注意力机制?
支付宝 v3 验签如何实现
Linux PCIe驱动框架分析(第三章)
史上最全架构师知识图谱
基于R语言的糖尿病检测模型准确率97%
利用Hugging Face中的模型进行句子相似性实践
Mybatisplus集成springboot完成分页查询
Jmeter和Postman那个工具更适合做接口测试?
-
原文地址:https://blog.csdn.net/jisuanji2606414/article/details/126180283