1760C - Advantage - CodeForces Solution


data structures implementation sortings *800

Please click on ads to support us..

Python Code:

t = int(input())

for essa in range(t):
	n = int(input())
	s = list(map(int, input().split()))
	posortowane = sorted(s)
	for i in range(n):
		if s[i] == posortowane[-1]:
			print(s[i] - posortowane[-2], end = " ")
		else:
			print(s[i] - posortowane[-1], end = " ")
	print()

'''

1
4
4 7 3 5

5
4
4 7 3 5
2
1 2
5
1 2 3 4 5
3
4 9 4
4
4 4 4 4

'''

C++ Code:

#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define endl "\n"
#define len length()
#define begin begin()
#define end   end()
#define num(a,s) count(a.begin,a.end,s)     
#define nsort(a) sort(a.begin,a.end)        //normal sort
#define rsort(a) sort(a.rbegin(),a.rend())  //reverse sort
#define psort(a) sort(a,a+n)                //pair sort
#define rev(a)   reverse(a.begin,a.end)
#define PB push_back
#define PI 3.1415926535
// #define n(x) x-'0'
#define x first
#define y second



int main(){
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
    int tc;     cin>>tc;
    for(int i=0;i<tc;i++){
        int n;  cin>>n;
        vector<int> a(n);
        for(int j=0;j<n;j++)    cin>>a[j];
        int p=-1;
        int m1=0,m2=0;
        for(int j=0;j<n;j++){
            if(a[j]>m1){
                m1=a[j];
                p=j;
            }
        }
        for(int j=0;j<n;j++){
            if(j!=p)    m2=max(m2,a[j]);
        }
        for(int j=0;j<n;j++){
            if(j==p)    cout<<m1-m2<<" ";
            else        cout<<a[j]-m1<<" ";
        }
        cout<<endl;
    }
}    


Comments

Submit
0 Comments
More Questions

1178D - Prime Graph
1711D - Rain
534A - Exam
1472A - Cards for Friends
315A - Sereja and Bottles
1697C - awoo's Favorite Problem
165A - Supercentral Point
1493A - Anti-knapsack
1493B - Planet Lapituletti
747B - Mammoth's Genome Decoding
1591C - Minimize Distance
1182B - Plus from Picture
1674B - Dictionary
1426C - Increase and Copy
520C - DNA Alignment
767A - Snacktower
1365A - Matrix Game
714B - Filya and Homework
31A - Worms Evolution
1691A - Beat The Odds
433B - Kuriyama Mirai's Stones
892A - Greed
32A - Reconnaissance
1236D - Alice and the Doll
1207B - Square Filling
1676D - X-Sum
1679A - AvtoBus
1549A - Gregor and Cryptography
918C - The Monster
4B - Before an Exam