CHECHOC - Editorial

I am getting correct outputs during dry run but shows WA when I submit it. Can you please tell me what’s wrong.
https://www.codechef.com/viewsolution/36033153

I am getting correct outputs during dry run but shows WA when I submit it. Can you please tell me what’s wrong. Here’s the code:
https://www.codechef.com/viewsolution/36033153

Can any one please find the error in this logic

int n,m;
int x,y;
cin>>n>>m>>x>>y;

    int F = x, S = y-x; if(S>x) S=x;  // if(y-x>x = = y>2x) S=x  , fill x everywhere
    if(y<x)  {  // filling y & 0 
        F=y; S=0;
    }
   
     int ans=0;
    
        int lw = n*m/2;

        int hi = n*m-lw; // if n*m is odd , lw= odd/2 and hi = n*m-lw. For 3*3 , lw= 4, hi = 5 
      
        ans=hi*F+lw*S;       


    cout<<ans<<"\n";

What’s wrong with my Solution?

HELP ME
I have checked for many test case but the answer is same those which are accepted.
{
ll n,m,x,y, sum=0;
cin>>n>>m>>x>>y;
if(y-x>x)
cout<<nmx<<"\n";
else{
if(n%2==0 ||m%2==0)
cout<<(nmx+nm(y-x))/2<<"\n";
else
cout<<((nm)/2+1)x+(nm/2)(y-x)<<"\n";
}

whats wrong with my code i m getting wa?

#include<bits/stdc++.h>
using namespace std;
typedef long long int ll;
int main()
{
    ll t,n,m,x,y,sum,ele1,ele2,ele,i;
    cin>>t;
    while(t--)
    {
        cin>>n>>m>>x>>y;sum=0;
        if(y<=x)
        {
            ele1=y;
            ele2=0;
        }
        else
        {
            ele1=x;
            ele2=y-x;
        }
        ele=ele1;
        for(i=0;i<n*m;i++)
        {
            sum+=ele;
            if(ele==ele1)
            ele=ele2;
            else
            ele=ele1;


        }
        cout<<sum<<endl;

    }
}

can some one tell me what is wrong in my code
https://www.codechef.com/viewsolution/35977216

try for n=1,m=1 x=2 and y=3
ans should be x that is 2

Same here bro! :face_with_head_bandage:

Can’t find for which case the code is giving wrong answer. I tried almost all cases i can come up with.
Please help i am trying from hours.
/* package codechef; // don’t place package name! */

import java.util.;
import java.lang.
;
import java.io.*;

/* 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
Scanner sc=new Scanner(System.in);
int t= sc.nextInt();
while(t–>0)
{
int n=sc.nextInt();
int m=sc.nextInt();
int x=sc.nextInt();
int y=sc.nextInt();

	    if(n*m==1)
	    System.out.println(x);
	    else
	    {
	    while(x>y)
	    x--;
	    int z=x;
	    while(x+z>y)
	    z--;
	    int candies=0;
	        //System.out.println("x="+x+"y="+y+"z="+z);
	        boolean putx=true;
	        for(int i=0;i<m;i++)
	        {
	          //  System.out.println("m="+m+"i="+i);
	            if(putx)
	            {
	                candies=candies+x;
	                putx=false;
	            }
	            else
	            {
	                candies=candies+z;
	                putx=true;
	            }

	        }
	      //  System.out.println(candies);
	        candies=candies*n;
	        System.out.println(candies);
	    }
	    
	}
}

}

CAN ANYBODY TELL FOR WHICH TEST CASES THIS SOLUTION IS WRONG?
I CANNOT GET WHY THIS SHOWS WRONG ANSWER!!!

#include “bits/stdc++.h”
using namespace std;
#define max(a, b) (a < b ? b : a)
#define min(a, b) ((a > b) ? b : a)
#define mod 1e9 + 7
#define FOR(a, c) for (int(a) = 0; (a) < ©; (a)++)
#define FORL(a, b, c) for (int(a) = (b); (a) <= ©; (a)++)
#define FORR(a, b, c) for (int(a) = (b); (a) >= ©; (a)–)
#define INF 1000000000000000003
typedef long long int ll;
typedef vector vi;
typedef pair<int, int> pi;
#define F first
#define S second
#define PB push_back
#define POB pop_back
#define MP make_pair
int main()
{
ios::sync_with_stdio(0);
cin.tie(0);
int T;
cin >> T;
while (T–) {
int n,m,x,y;
cin >>n>>m>>x>>y;
int sum=0;
int sq=nm;
if(sq%2==0)
{
if((y/2)<=x)
sum=y
(sq/2);
else
sum=xsq;
}
else
{
if((y/2)<=x)
{
sum=x
(sq/2+1)+((y-x)sq/2);
}
else
{
sum=x
sq;
}
}
cout<<sum<<endl;
}
return 0;
}

Can anyone please tell when this will give wrong answer.
I tried almost every case including n==m==1.
https://www.codechef.com/viewsolution/36037845

Can anyone help me to debug this code( CodeChef: Practical coding for everyone )

Try

1 1 10 1

Correct ans

10

1 Like

Can anyone plz help me where did I go wrong?
https://www.codechef.com/viewsolution/36038584

int n,m;
int x,y;
cin>>n>>m>>x>>y;
int F = x, S = y-x; if(S>x) S=x; // if(y-x>x = = y>2x) S=x , fill x everywhere
if(y<x) { // filling y & 0
F=y; S=0;
}
if(n==m==1)
F=x,S=x; //Edge case
int ans=0;

    int lw = n*m/2;

    int hi = n*m-lw; // if n*m is odd , lw= odd/2 and hi = n*m-lw. For 3*3 , lw= 4, hi = 5 
  
    ans=hi*F+lw*S;       


cout<<ans<<"\n";
1 Like

Got it thanks !

1 Like

#include<bits/stdc++.h>
using namespace std;
typedef long long int ll;
int main()
{
ll t,n,m,x,y,sum,ele1,ele2,ele,i;
cin>>t;
while(t–)
{
cin>>n>>m>>x>>y;sum=0;
if(y<=x)
{
ele1=y;
ele2=0;
if(n==m==1) //Corner case
ele1=x;
}
else
{
ele1=x;
ele2=y-x;
}
ele=ele1;
if(y-x>x) //if y>2x
ele2=x;
for(i=0;i<n*m;i++)
{
sum+=ele;
if(ele==ele1)
ele=ele2;
else
ele=ele1;

    }
    cout<<sum<<endl;

}

}

1 Like
#include <bits/stdc++.h>

using namespace std;

int32_t main() {

ios_base::sync_with_stdio(false);
cin.tie(NULL);
cout.tie(NULL);

int t;
cin >> t;

while (t–) {
int n, m, x, y;
cin >> n >> m >> x >> y;
float r = (float)y / 2;

if (n == 1 && m == 1) {                
  cout << x << endl;                                  /* This is the edge case(1X1 matrix)*/     
} else {
  if (2 * x <= y) {                               
    cout << n * m * x << endl;                        /*If x is less than half of y, even if we fill x on both adjacent sides, some of both will be less than or equal to y*/
  }                                                     
  else if (x > y) {
    if (n * m % 2)
      cout << ((n * m) / 2 + 1) * y << endl;          // If x is greater than y
    else {
      cout << (y * ((n * m) / 2)) << endl;
    }

  }
   else {
    if (n * m % 2) {
      cout << ((y - x) * ((n * m) / 2)) + (x * ((n * m) / 2 + 1)) << endl;   // if x > y/2 && x <= y
    } else {

      cout << (y * ((n * m) / 2)) << endl;
    }
  }
}

}
return 0;
}Preformatted text

suppose y=100 and x=10
so in else
your ele2 = 100-10=90;
but 90 is not allowed to put because maximum is x i.e. 10 ;
s0,
You should write ele2 = min(x,y-x)

1 Like