Skip to content

Commit 9ce47d3

Browse files
Merge pull request #338 from Anushh23/codechef-2
Added PAIRDIST to easy category
2 parents 2995b9f + a07f97b commit 9ce47d3

File tree

2 files changed

+63
-0
lines changed

2 files changed

+63
-0
lines changed
Lines changed: 62 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,62 @@
1+
#include<bits/stdc++.h>
2+
using namespace std;
3+
typedef long long int ll;
4+
#define fast ios_base::sync_with_stdio(0), cin.tie(NULL), cout.tie(NULL)
5+
#define endl "\n"
6+
#define ii pair<ll,ll>
7+
#define ic pair<char,ll>
8+
#define pb push_back
9+
#define vi vector<ll>
10+
#define popb pop_back
11+
#define all(v) (v).begin(), (v).end()
12+
#define F first
13+
#define S second
14+
const int N=1e5+1;
15+
ll M= 1e9+7;
16+
ll v1,v2;
17+
18+
int main()
19+
{
20+
fast;
21+
ll tt=1,i,j,num;
22+
cin>>tt;
23+
for(num=1;num<=tt;num++)
24+
{
25+
ll n;
26+
cin>>n;
27+
vector<ll>a(n);
28+
vector<ii>v;
29+
for(i=0;i<n;i++)
30+
{
31+
cin>>a[i];
32+
v.pb({a[i],i});
33+
}
34+
sort(all(v));
35+
vector<pair<ll,pair<ll,ll>>>aa;
36+
if(n<=4)
37+
{
38+
cout<<"YES"<<"\n";
39+
ll a1=0,a2=0;
40+
aa.pb({v[0].S,{a1,a2}});
41+
for(i=1;i<v.size();i++)
42+
{
43+
ll x1,x2;
44+
if(i==1){x1=a1+v[i].F;x2=a2+v[i-1].F;}
45+
if(i==2){x2=a2+v[0].F;x1=a1-v[i].F;}
46+
if(i==3){x1=a1;x2=v[0].F+v[i].F;}
47+
aa.pb({v[i].S,{x1,x2}});
48+
}
49+
sort(all(aa));
50+
for(i=0;i<aa.size();i++)
51+
{
52+
cout<<aa[i].S.F<<" "<<aa[i].S.S<<"\n";
53+
}
54+
55+
}
56+
else
57+
{
58+
cout<<"NO"<<"\n";
59+
}
60+
}
61+
62+
}
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
### https://www.codechef.com/COOK133B/problems/PAIRDIST

0 commit comments

Comments
 (0)