I generaly got a error ! can anyone help me!
Here is my code:
#include
using namespace std;
int main() {
int t,n,x,sum;
cin>>t;
while(t–){
cin>>n;
int a[n];
for(int i=0;i<n;i++){
cin>>a[i];
}
x=a[0]+a[1];
for(int i=0;i<n;i++){
for(int j=i+1;j<n;j++){
sum=0;
sum=a[i]+a[j];
if(sum<=x){
x=sum;
}
}
}
cout<<x<<"\n";
}
return 0;
}
Whats wrong in it?
ssjgz
2
Please either format your code or (better!) link to your submission - the forum software has mangled it and it won’t compile!
Also - what Problem are you trying to solve?
That should probably result in TLE. Why not try finding the two smallest numbers (1^{st} minimum and 2^{nd} minimum) and find their sum?
Edit: Just Compiled your code.
CPP Code
#include <bits/stdc++.h>
using namespace std;
int main() {
int t,n,x,sum;
cin>>t;
while(t--){
cin>>n;
int a[n];
for(int i=0;i<n;i++){
cin>>a[i];
}
x = a[0] + a[1];
for(int i=0;i<n;i++){
for(int j=i+1;j<n;j++){
sum=0;
sum=a[i]+a[j];
if(sum<=x){
x=sum;
}
}
}
cout<<x<<"\n";
}
return 0;
}
This is not resulting in SIGTSTP
error. The verdict is TLE.