https://www.codechef.com/viewsolution/32942052
Finally submitted. Thank you all
I guess it won’t make your code correct, but why bother writing a sort function.
We already have sort(w, w+y);
I don’t know C++. so I am writing code in C. For upper_bound(), initially I read about that then applied in my code.
I’ll suggest that you explore some basic C++ features that are very helpful in CP. For example, I modified your 79 - liner AC code, and just modified a few stuff like unnecessary headers (If you include <bits/stdc++.h>
, you don’t need to explicitly write many headers such as <iostream>, <stdio.h>
, etc.) and changed your Quick Sort code and modified it to std::sort
, and the same code became 38 lines. Also, std::lower_bound
and std::upper_bound
can be implemented using binary search, but again, why bother to do so when you have it inbuilt? Short codes help in CP, because shorter the code, easier it is to debug (less lines where you can make an error).
PS: Even C has qsort()
, but apparently C++ std::sort()
is faster.
Thanks for ur valuable suggestion. I will surely learn C++.
Also read about STL. This will really help you.
Hi,
I started learning C++ yesterday from GFG. I covered basics, string and function. some topics are like same as in C. Currently I started STL, it’s very interesting and skipped oops concept.
Is it necessary to cover oops for competitive programming?
I think it is not needed for cp
I am also getting this error
here is my code
#include <stdio.h>
int main(void) {
// your code goes here
int n,i,j,len,s=0,o,k;
scanf("%d",&n);
for (i=0;i<n;i++){
scanf("%d",&len);
int num[len];
for (j=0;j<len;j++){
scanf("%d",&num[j]);
s=s+num[j];
}
o=0;
while (s!=0){
o++;
for (k=0;k<len;k++){
while(num[k]!=0){
if (num[k]==1){
num[k]=num[k]-2*0;
if(num[k]>0){
num[k]=num[k]*-1;
}
}
else{
num[k]=num[k]-2*1;
if(num[k]>0){
num[k]=num[k]*-1;
}
}
s=s+num[k];
}
}
}
printf("%d\n",o);
}
return 0;
}
Plz anyone help me to resolve it asap ,bcoz this camp will end in 18 hours https://www.codechef.com/MAY222D/problems/MAKEZERO