My issue
My code
#include <iostream>
#include<algorithm>
using namespace std;
int main() {
long test,N;
cin>>test;
for(long i=0;i<test;i++){
cin>>N;
int arr[N];
for(long j=0;j<N;j++){
cin>>arr[j];
sort(arr,arr+N);
}
cout<<arr[0]+arr[1]<<endl;
}
return 0;
}
Problem Link: SMPAIR Problem - CodeChef
@mounika772
I think u have figured out the logic of the code , yet u made some minute errors in the code.
u can use array for this question but vectors are pretty much handy.
I have pasted my correct code below , hope this helps!!
include <bits/stdc++.h>
define pb push_back
using namespace std;
int main() {
// your code goes here
int t;
cin>>t;
while(t–)
{
vectorv;
int n;
cin>>n;
for(int i=0;i<n;i++)
{
int a;
cin>>a;
v.pb(a);
}
sort(v.begin(),v.end());
cout<<v[0]+v[1]<<endl;
}
return 0;
}