The first problem can be solved in O(1) time complexity per test case,
here is my code in cpp
#include <bits/stdc++.h>
using namespace std;
int main(){
ios::sync_with_stdio(false);
int t;
cin >> t;
while(t--){
int n,k,s;
cin>>n>>k>>s;
int sundays = s/7;
int TOTAL = k*s;
int buy = n*(s-sundays);
if(buy < TOTAL){
cout << "-1" << endl;
}else{
cout << ceil(float(TOTAL)/n) << endl;
}
}
return 0;
}
The logic: If total number of chocolates needed for S days is MORE that the number of chocolates possible to buy in that (S-number of Sundays) days then it isn’t possible to survive, else it is just ceil(float(TOTAL Needed chocolates)/(maximum number of chocolates possible to buy per day i.e. N )) … ceil() function is used as integer division will exclude some days at the end. i.e. a box of chocolates should be bought at the day number of chocolates left is less than K.
I followed a bit general approach for the second problem as I didn’t have enough time to actually think of all the edge cases. So I saw in the test cases that after the 3rd element there is a pattern. So I stored that pattern in a vector and checked how many times it will get repeated in the final number.
And then I just added first three numbers+(sum of vector)*(number of times it is repeated in the final number) + remaining numbers.If this sum is divisible by 3, then the answer is YES otherwise,NO.
for e.g if i take the test case 13 10 8
then on the first coming sunday the chocolates we would be having are less than k. So the answer should be -1. But the correct answer is 7. What am i missing? coz for this test case my code is giving output as -1
Initially I waited for few mins before coding and then I saw multiple WAs,so I thought O(S) might be missing some corner cases. I was sure about BS solution,so implemented it
Lol, I was hunting for cakewalk problem in first few min my order was-
>Opened p4. ".....He asked to find the matrix? DEFINITELY NOT CAKEWALK"
>p5 has "graph" in it. Lol graph no cakewalk.
>Great array...hmmm. Might be. (2 min after reading the statement and thinking "Noo....please this be p4.....XD
>Multhree "YEAH This can be cakewalk!!" (Submitted a soln- got WA- "Hmm...Not cakewalk I guess lol")
>And finally chocoland lol.