My issue
Time Limit Exceeded with my code…
My code
#include <iostream>
using namespace std;
int ConsectutiveSum(int x){
if (x == 1){
return 1;
}
int ans = x + ConsectutiveSum(x-1);
return ans;
}
int main() {
// your code goes here
int t;
cin>>t;
while (t--){
int N, M;
cin>>N>>M;
int a[N];
for (int i = 0; i < N; i++){
cin>>a[i];
}
for (int i = 0; i < N; i++){
for(int j = i+1; j < N; j++){
if (a[j] == a[i] && a[i] != 0){
a[j] = 0;
}
}
}
int sum = 0;
for (int i = 0; i < N; i++){
sum += a[i];
}
int K = ConsectutiveSum(M);
if (K == sum){
cout << "No" << endl;
}
else{
cout << "Yes" << endl;
}
}
return 0;
}
Learning course: Level up from 1* to 2*
Problem Link: CodeChef: Practical coding for everyone