Contest 1 - Hints to Problems [OFFICIAL]

/* 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){
long k = sc.nextLong()-2;
long d0 = sc.nextLong();
long d1 = sc.nextLong();

	    long x = (d0+d1)%10,y=(d0+d1)%3;
	    if(k>7){
	        if(x==0){
	            k=0;
	        }
	        if(x==1){
	            k-=1;
	            y = (y+1+2*(k/4))%3;
	        }
	        else if(x==2){
	            y = (y+2*(k/4))%3;
	        }
	        else if(x==3){
	            k-=2;
	            y = (y+2*(k/4))%3;
	        }
	        else if(x==4){
	            k-=3;
	            y = (y+2*(k/4))%3;
	        }
	        else if(x==5){
	            k-=1;
	            y = (y+2)%3;
	        }
	        else if(x==6){
	            k-=1;
	            y = (y+2*(k/4))%3;
	        }
	        else if(x==7){
	            k-=4;
	            y = (y+1+2*(k/4))%3;
	        }
	        else if(x==8){
	            k-=2;
	            y = (y+2+2*(k/4))%3;
	        }
	        else if(x==9){
	            k-=3;
	            y = (y+2+2*(k/4))%3;
	        }
	        k%=4;
	        if(k==1 || k==3)
	            y = (y+2)%3;
	    }
	    else{
	        for(int i=0;i<k;i++){
	            y = (y+x)%3;
	            x = (x*2)%10;
	        }
	    }
	    if(y%3==0)
	        System.out.println("YES");
	    else
	        System.out.println("NO");
	}
}

}

can someone tell me what is the problem with this code.

Try sorting the budgets array.This way you can calculate the revenue that a price would generate in O(1) and by traversing over all the budgets (of the sorted budgets array) , you can choose the max_REVENUE.

I am struck at Mul of 3 question, please tell me if I am going in right direction.
As 8, 4, 2, 6 numbers would repeat after certain addition, like eg: for 13 8 1 ==> 8+1+9(after here numbers would repeat in order they started with 8)+8+6+2+4…etc. 8+4+2+6 = 20, so 13-3 = 10(excluding 8, 1, 9) → 10%4 =2(at last 2 digits 8, 6 would be left out). add all of them ==> ((10%4)*20)+(8+1+9)+(8+6) = 72==> 72%3 is true so print “YES”.

When i am trying to execute this problem in Codechef ide, i get time out whereas other ide works fine. How do i solve this problem?

Solution Link:
https://www.codechef.com/viewsolution/37143433

why isnt this working for carvans ?

#include <bits/stdc++.h>
using namespace std;
typedef long long ll;

int main(){
int t;
cin >> t;
while(t–){
int n;
cin >> n;
int arr[n];
for(int i=0; i<n; i++){
cin >> arr[i];
}
int temp = n;
for(int i=0; i<n-1; i++){
if(arr[i] > arr[i+1]){
continue;
}
else{
temp-- ;
}
}
cout << temp << “\n”;
}
}

hi i have followed steps of “MULTHREE” logic properly properly with referenct to c++ language but it is still saying incorrect. please help me out with this.and even i am getting the expected result in “MULTHREE” when i am hitting the code. please help me out where i am getting wrong.

Question link → Question
Reference link video ->( Solution reference main part from (54:36 to 1:40:46))

My Solution:- my Solution

Hi. Can anyone help me with my “MULTHREE” solution? It’s getting a TLE but I’m not sure why. Thanks.

https://www.codechef.com/viewsolution/39298753

For the Smartphone problem I sorted the array in ascending . so for the 2nd example I got {3,21,33,40,65} and my answer would be middle element times no. of elements after that (including it) i.e 99. similarly for the 1st example i would get {14,20,30,53} and the answer would be 30(middle element) *no.of elements after that. where am i wrong

(a+b) mod c = (a mod c + b mod c) mod c;

https://www.codechef.com/viewsolution/41548359
https://www.codechef.com/viewsolution/41547342

Both are giving error & I have no idea why!!

In the first one: 2^n; n tends to be very very large and therefore most likely encounters time out.

Hey, for MULTHREE how does one recognize the powers of 2 pattern that went along with the hint 2 and hint 3. Are there any specific problems where the recurrence (of powers of 2) occurs?

@anon57017914 The first thing I noticed is that “k” is not int it ranges from 2<k<10^12. It should be of type long long

I am getting wrong answer for “Multiple of three”.
https://www.codechef.com/viewsolution/41799285

Any help is appreciated

Hi dear, I was using the same logic. Still my code is WA.
sharing the link for my solution, if you could help :bowing_woman:
https://www.codechef.com/viewsolution/43901592

Consider the test input:

1                                                                       
2 INDIAN
TOP_CONTRIBUTOR
CONTEST_WON 1
1 Like

I don’t understand why but for this it outputs 1

Start debugging then :slight_smile: For a start, figure out how many laddus your program calculates, and how many it should calculate.

1 Like

okay got it , thank you for the help :heart:

1 Like

thanks again. It works fine now

1 Like

please help with the solution
https://www.codechef.com/viewsolution/43909055
what is wrong in this?