Admin , can i please get the in.txt and out.txt for BESTBATS. My answer is working correctly for the testcases I have given(verified),but codechef’s judge is reporting wrong answer.
Here is my code–
#include
#include
#include<stdio.h>
#include
using namespace std;
int main(){
int cases,ways = 1,i,j,n,m,a[11],c[11],e[11],l = 0,t = 0;
vector b,d;
scanf("%i",&cases);
while(t < cases){
for(i = 0 ; i < 11 ; i++){
scanf("%i",&a[i]);
c[i] = 0,e[i] = 0;
}
scanf("%i",&n);
sort(a,a + 11);
for(i = 0 ; i < n ; i++){
b.push_back(a[10 - i]);
}
for(i = 0 ; i < 11 - n ; i++){
d.push_back(a[i]);
}
// for(i = 0 ; i < n ; i++){
// printf("%i “,b[i]);
// }
// printf(”\n");
// for(i = 0 ; i < 11 - n ; i++){
// printf("%i ",d[i]);
// }
for(i = 0 ; i < b.size() ; i++){
for(j = i + 1 ; j < b.size() ; j++){
if(b[i] == b[j]){
c[l]++;
b.erase(b.begin() + j);
j--;
}
else
break;
}
c[l]++;
l++;
}
/*
printf(“the b is\n”);
for(i = 0 ; i < l ; i++){
printf("%i “,b[i]);
}
printf(”\nthe c is\n");
for(i = 0 ; i < l ; i++){
printf("%i “,c[i]);
}
printf(”\nthe d is\n");
for(i = 0 ; i < 11 - n ; i++){
printf("%i ",d[i]);
}
*/
l = 0;
for(i = 0 ; i < b.size() ; i++){
for(j = 0 ; j < 11 - n ; j++){
if(b[i] == d[j])
e[l]++;
}
l++;
}
/*
printf("\nthe e is\n");
for(i = 0 ; i < l ; i++){
printf("%i ",e[i]);
}
printf("\n");
*/
for(i = 0 ; i < l ; i++){
if(e[i] == 0){
ways = ways*1;
}
else{
m = c[i];
c[i] = c[i] + e[i];
for(j = 0 ; j < m ; j++){
ways = ways*c[i];
c[i]--;
}
ways = (ways)/2 ;
}
}
printf("%i\n",ways);
t++,ways = 1,l = 0,b.clear(),d.clear();
}
return 0;
}
anyone can verify for some test cases by running it.
I could not follow your completely, i can figure out that you are thinking very complexly.
Think of it as this :
- We need to pick the players in decreasing order of their scores.
- If there are x players with the score ‘s’ and we had to pick y more players.
- Now if x < y, then update y = y - x, ie. you have to pick them in order to make the largest sum.
- If x > y, then you have to any y players from the x players as any y number of them would make the largest sum.
After reading the above points now try to make the code.
Correct me, if I’m wrong, but answer for
1
2 2 2 2 2 2 2 2 2 2 2
5
is 332640
, your code returns 27720
.
Here is ideone link - 1a2GHR - Online C++ Compiler & Debugging Tool - Ideone.com
codechef does not provide the test cases.
BESTBATS-codechef easy,no. of successful submissions - 1071
Link to your solution is almost always better, especially when you add no comments, just paste the content…
Here it is - CodeChef: Practical coding for everyone