How to find constrains, i don't understand constrains and how to implement it?

Here is my code for CHFICRM problem find the edge cases please!!!

#include
using namespace std;

int main()
{
int x ;
cin>>x;
string c[x]={};
if(x<=100){

for(int i=0;i<x;i++){
int count =0;
int y;
cin>>y;
if(y>=1000){
break;
}
int a[y] ={};
for(int j=0;j<y;j++){
int g;
cin>>g;
if(g==5 || g==10 || g==15){
a[j]=g;
}else{
break;
}
}

for(int k=0;k<y;k++){
if(a[0]==10 || a[0]==15) {
c[i]=“NO”;
break;}

if(a[k]==5){
count = count + 5;

    c[i]="YES";

}else if(a[k]==10){

count = (count - 5);
if(count < 0 ){
    c[i]="NO";
    break;

}}else if(a[k]==15){

count = (count - 10);
if(count < 0 ){
    c[i]="NO";


    break;

}}else {

    break;

}

}
}
for(int l=0;l<x;l++){

cout<<c[l]<<endl;

}

}
}

I will start with some posting recommendations.

  1. Link a submission instead of posting your code, that gives us more information.
    In this case: https://www.codechef.com/viewsolution/34353427
  2. Give an explanation of what your code does. You might even find a flaw in your logic by trying to explain it, and otherwise it will help people who want to help to understand your code

Secondly: the question in your title
Constraints are constraints on the input Codechef can give to your program. If your program takes as input an integer N, and a constraint says 1\leq N\leq 10000 that means that Codechef guarantees that for each test case N will have a value between 1 and 10000. You don’t need to “implement” constraints. They are listed because for harder problems you will need this information to determine if an algorithm is fast enough.

Your code, simplified
#include<iostream>
#include<cmath>
using namespace std;

int main()
{
	int numCase ;
	cin>>numCase;
	for(int i=0;i<numCase;i++) {
		int numTransaction;
		cin>>numTransaction;

		int count = 0;
		string answer = "YES";
		for(int k=0;k<numTransaction;k++) {
			int coin;
			cin >> coin;

			if(coin==5) {
				count = count + 5;
			} else if(coin==10) {
				count = (count - 5);
				if(count < 0 ){
					answer="NO";
					break;
				}
			} else if(coin==15) {
				count = (count - 10);
				if(count < 0 ) {
					answer="NO";
					break;
				}
			}
		}
		cout << answer << endl;
	}
}

Lastly an edge case of your program:

Edge Case

You have not considered that chef can return 10-coins if someone pays with a 15-coin.

1 Like

sorry for my stupid way of asking question. i’m new here but thank you so much for taking your valuable time and correcting my stupid code.

and now i get it why my answer was failing.

Again ty so much

It’s not a “stupid way of asking a question”, they are among the most common ways people ask questions here. Some don’t even link the problem! The suggestions I gave are to improve questions you may ask in the future.

1 Like

ok last question because you are a 5 star rated coder i wanna know what topics are important in c++ except these (what extra do i need to know)

  1. variables 2. if-else 3. loops 4. strings 5. array 6. function 7. still learning stl’s 8. still learning DS & algo

do i need to know pointers – although i know basic pointer(i know what it is? never solved questions)

what else do i need to know in c++ ? i mean topics .
i tried to find the answer on the internet and i was not able to find it !!

plz list the topic other than above mentioned !!!

first one item you probably missed: IO
One important one you missed is algorithmic design paradigms. These are some “default” methods to solve a problem. These include Brute Force, Backtracking, Greedy, Divide and Conquer, and most importantly Dynamic Programming.

With regards to pointers: the concept of a pointer is important in understanding data-structures. But in practice I rarely use them in competitions because most data-structures are already pre-defined in the standard library.

I don’t think you can break after answer = "NO", won’t that affect the input of the next test case? I did this mistake in the contest and spent ample time to debug this.

1 Like

how did u got 4* so fast in just 3 months ?

You are right, I didn’t think about that. Removing the break statements should resolve that problem

1 Like

You’re talking about my rank this contest? This contest was relatively easy (for me). All the problems in Div. 2 were more or less puzzle type questions, and only CONTAIN was an algorithm based question. So I was able to solve all the questions.

Also, my learning curve hit a steep shoot up after the may challenge. I went thought the editorials of all the problems (including Div 1) and learnt all the algorithms and data structures used there. And I’m sure you can also grab a great rank in the upcoming contests! Happy coding :v:.

[UPD]: Just realized you meant 4 Star. Well, the answer to that is pretty much the same thing.

1 Like

man u r a genius…i will be needing your help …plz point me to good resources…also tell me what should i learn now…i know 1. IO 2. variables 3. if-else 4. loops 5. strings 6. functions 7. array what else do i need to learn…i’m learning stl’s and ds & algo…

do i need to know more in C++ or do u think its enough?

1 Like

Haha, it’s just practice. Continue learning stl and implement it for now. I solved a lot of problems on leetcode, which is how I learnt stl. For algo and DS, participating in long contests is more than enough!

As @spaanse has mentioned earlier (I guess twice?) start with divide and conquer, backtracking and Greedy algorithms. (You can find these tags in leetcode problems section, I’m not aware of CodeChef practice area).

And then start learning all dynamic programming algorithms, like Longest Increasing Subsequence, Longest Common Subsequence, etc and solve a lot of problems on DP.

After that you can move on to graphs. And occasionally you can learn some string algorithms, and pattern matching. (But not before mastering Divide & Conquer and DP).

After these, you’ll eventually stumble upon advanced DS and Algorithms when you keep solving problems. After any contest, read the editorial for all the problems and try to learn the DSA implemented there!