You are on page 1of 4

CODECHEF ASSIGNMENT -3 ANSWERS : HAAM’S

ASSIGNMENT LINK - https://www.codechef.com/CUPP2101

1. The Smallest Pair -- SMPAIR


#include<bits/stdc++.h>
using namespace std;
int main()
{
long long int n;
cin>>n;
while(n--)
{
long long int m;
cin>>m;
vector<long long int >v(m);
for(int i=0;i<m;i++)
cin>>v[i];
sort(v.begin(),v.end());
cout<<v[0]+v[1]<<endl;
}
}

2. Qualifying to Pre-Elimination -- QUALPREL


#include<bits/stdc++.h>
using namespace std;

int main ()
{
int t,a,b;
cin >> t;
while(t--)
{
cin >> a >> b;
int arr[a];
int c = 0;
for(int i = 0; i < a; i++)
cin >> arr[i];

JOIN HAAM’S COMMUNITY TELEGRAM GROUP - https://t.me/HAAMSCOMMUNITY


CODECHEF ASSIGNMENT -3 ANSWERS : HAAM’S
sort(arr, arr + a, greater<int>());
int index = arr[b-1];
for(int i = 0; i < a; i++)
{
if(arr[i] > index || arr[i] == index)
c++;
}
cout << c << endl;
}
}

3. Missing a Point --- PTMSSNG


(PHYTHON CODE)

t=int(input())
while(t):
r=int(input())
a=[]
b=[]
for _ in range(1,4*r):
x,y=map(int,input().split())
a.append(x)
b.append(y)
x1=0
y1=0

for i in a:
x1=x1^i
for i in b:
y1=y1^i
print(x1,y1)
t=t-1

4. ChefWatson uses Social Network -- BOOKCHEF


#include<bits/stdc++.h>
using namespace std;

int n;
int arr[1000+5];
int special(int a){
for(int i=0;i<n;i++){
if(arr[i]==a)
return 1;
}

JOIN HAAM’S COMMUNITY TELEGRAM GROUP - https://t.me/HAAMSCOMMUNITY


CODECHEF ASSIGNMENT -3 ANSWERS : HAAM’S
return 0;
}
int main(){
int m;
cin >> n >> m;
// int arr[n];
for(int i=0;i<n;i++)
cin >> arr[i];
pair<int,string> temp[m];
int x[m];
for(int i=0;i<m;i++){
cin >> x[i] >> temp[i].first >> temp[i].second;
}
int j=0;
pair<int,string> temp1[n];
for(int i=m-1;i>=0;i--){
if(special(x[i])){
temp1[j].first=temp[i].first;
temp1[j].second=temp[i].second;
j++;
temp[i].first=0;
//cout < temp[i].second << endl;
//temp[i].second=" ";
}
}
sort(temp1,temp1+n);
for(int i=n-1;i>=0;i--)
cout << temp1[i].second << endl;
sort(temp,temp+m);
for(int i=m-1;i>=0;i--){
if(temp[i].first==0)
continue;
else
cout << temp[i].second << endl;
}
return 0;
}

5. Total Correct Submissions -- TOTCRT


#include<bits/stdc++.h>
using namespace std;
int main()
{
long int t;
cin>>t;
while (t--)

JOIN HAAM’S COMMUNITY TELEGRAM GROUP - https://t.me/HAAMSCOMMUNITY


CODECHEF ASSIGNMENT -3 ANSWERS : HAAM’S
{
unordered_map<string,int> mp;
int n;
cin>>n;
for (int i = 0; i < n*3; i++)
{
string s;
int temp;
cin>>s>>temp;
if (mp.find(s)!=mp.end())
{
mp[s]+=temp;
}
else
{
mp.insert({s,temp});
}

}
vector<int>v;
for (auto i: mp)
{
v.push_back(i.second);
}
sort(v.begin(),v.end());
for (int i = 0; i < v.size(); i++)
{
cout<<v[i]<<" ";
}
cout<<endl;
}
return 0;
}

JOIN HAAM’S COMMUNITY TELEGRAM GROUP - https://t.me/HAAMSCOMMUNITY

You might also like