My issue
hello
actually there is a problem on codeforces which i solved but it is giving wrong answer in test case 2 and i am unable to understand why? i am attahcing the question link and my submission link here.
this is the submission link:
sorry here we cannot post links , so i will attach my code in below and will give the name of the question on codeforces
Name of the question : B. Mark the Dust Sweeper(900 rating index B)
My code
#include <bits/stdc++.h>
using namespace std;
int main() {
int t;
cin >> t;
while (t--) {
int n;
cin>>n;
int a[n];
int f=0;
long long int count=0;
for(int i=0;i<n;i++) {
cin>>a[i];
}
for(int i=0;i<n;i++) {
if(a[i]!=0){
f=i;
break;
}
}
if(f==n-1){
cout<<"0"<<endl;
}
else{
for(int i=f;i<n-1;i++){
if(a[i]==0){
count+=1;
//cout<<"This statement is running for a[i]==0"<<endl;
}
else{
count+=a[i];
//cout<<"This statement is running for a[i]!=0"<<endl;
}
//cout<<"Value of count after "<<i<<"is : " <<count<<endl;
}
//cout<<"Final value of count is : "<<endl;
cout<<count<<endl;
}
}
return 0;
}
Learning course: Arrays using C++
Problem Link: Cost of Groceries Practice Problem in - CodeChef