Since you have declared your variable sum outside the for loop of testcases it retains the value of previous testcases. You can do two things either declare variable sum inside the for loop of testcase or after last line of code do “sum=0;”. This will reset you sum to be zero for each testcase.
Also you have to print “No” instead of “NO” and “Yes” instead of “YES”
/* Name of the class has to be “Main” only if the class is public. */
class Codechef
{
public static void main (String[] args) throws java.lang.Exception
{
// your code goes here
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
int t = Integer.parseInt(br.readLine().trim());
for(int i=0;i<t;i++)
{
String a[]=br.readLine().trim().split(" ");
int sum=0;
for(int k=0;k<a.length-1;k++)
{
sum=sum+Integer.parseInt(a[k])Integer.parseInt(a[5]);
}
if(sum>(245))
{
System.out.println(“YES”);
}
else
{
System.out.println(“NO”);
}
}
}
}
WHEN I SUBMIT IT IS SHOWING WRONG ANSWER
PLEASE HELP WHERE IS THE MISTAKE IN CODE
The if condition should be if(sum>120) because he will have 120 hours in weekdays(24*5).
And you have to print “Yes” instead of “YES” and “No” instead of “NO”.
for i in range(t):
l = []
arr = list(map(int,input().split()))
p = arr.pop()
arr = [i*p for i in arr]
new = sum(arr)
if new > 120:
print(“Yes”)
else:
print(“No”)
class Codechef
{
public static void main (String[] args) throws java.lang.Exception
{
Scanner sc = new Scanner(System.in);
int tcs = sc.nextInt();
while(tcs > 0) {
int sum = 0;
for(int i = 0; i<5; i++){
sum = sum + sc.nextInt();
}
int p = sc.nextInt();
if((sum * p) <= 120) {
System.out.println(“Yes”);
} else {
System.out.println(“No”);
}
tcs–;
}
#include<bits/stdc++.h>
using namespace std;
int main(){
int t,p;
cin>>t;
while(t--){
vector<int> a(5);
for(auto &it: a) cin>>it;
cin>>p;
for(int i=0;i<(int)a.size();i++){
a[i]=a[i]*p;
}
int x=accumulate(a.begin(),a.end(),0);
if(x>120)
cout<<"Yes\n";
else
cout<<"No\n";
}
return 0;
}
Why the above code shows Runtime Error(SIGCONT)?
Frustrating!
Please Help.
Its running just fine on my machine as well as geeksforgeeks IDE…I think something is wrong with CodeChef IDE !