@baljitsingh check for ->
1
6
0 0 0 2 2 2
This is working for all test cases .Still WA…It would be helful if anyone can tell the error…
#include<bits/stdc++.h>
using namespace std;
struct data
{
int g;
int pos;
};
bool myfunc(struct data e,struct data d)
{
return e.g>d.g;
}
int main()
{
int t,n;
scanf("%d",&t);
while(t–)
{
scanf("%d",&n);
int a[n],b[n];
int visited[n],i,j,s=0,f=0;
data c[n];
for(i=0;i<n;i++)
{
scanf("%d",&a[i]);
c[i].g=a[i];
c[i].pos=i;
visited[i]=0;
s=s+a[i];
if(a[i]>=n)
f=1;
}
if(s!=n || f==1)
printf("-1\n");
else
{
sort(c,c+n,myfunc);
/for(i=0;i<n;i++)
printf("%d %d\n",c[i].g,c[i].pos);/
for(i=0;i<n;i++)
{
for(j=c[i].pos+1;j<n;j++)
{
if(c[i].g==0)
break;
if(visited[j]==0)
{
c[i].g–;
visited[j]=1;
b[j]=c[i].pos+1;
}
}
for(j=0;j<c[i].pos;j++)
{
if(c[i].g==0)
break;
if(visited[j]==0)
{
c[i].g --;
visited[j]=1;
b[j]=c[i].pos+1;
}
}
}
for(i=0;i<n;i++)
printf("%d “,b[i]);
printf(”\n");
}
}
return 0;
}
hello sir. please help me where i made a mistake . i not able to know my mistake. after submitting my code i am getting wrong answer but i am not able to know where my mistake is? please help me . here is the link to my solution:- CodeChef: Practical coding for everyone
I can’t find mistake in following solution
using namespace std;
int main()
{
int T = 0;
int N = 0;
int sum = 0;
int tmp = 0;
bool flag = false;
int arr[100];
int arr1[100];
cin >> T;
for (int i = 0; i < T; i++)
{
flag = false;
sum = 0;
cin >> N;
for (int j = 0; j < N; j++)
{
cin >> arr[j];
//sum += tmp;
//if (sum>N || tmp >= N)
//{
// flag = true;
//}
}
for (int a = 0; a < N; a++)
{
sum += arr[a];
if (arr[a] >= N)
{
flag = true;
break;
}
if (sum > N)
{
flag = true;
break;
}
}
if (sum < N)
flag = true;
if (flag)
{
cout << -1 << "\n";
}
else
{
int count1 = 0;
for (int a = 0; a < N; a++)
{
for (int b = 0; b < N; b++)
{
if (b != a)
{
if (arr[b]>0)
{
arr[b]--;
cout << b + 1<<"\t";
}
}
}
/*
if (arr[a] != 0 && a!=N-1)
{
cout << a + 2<<" ";
}
else if (arr[a] != 0 && a == N - 1)
{
cout << 1;
}*/
}
cout << "\n";
}
}
return 0;
}
// int a[n]- is the input array for each test case
// int k[n] - is the array which stores the output.
vector k (n);
fill (k.begin(),k.end(),-1);
for(int j=n-1;j>=0;j–){
int x=a[j];
int m;
m=j-1;
if(k[0]!=-1)
m=n-1;
for (; m>=-1; m–){
if(x==0)
break;
if(m==-1){
m=n;
continue;
}
if(k[m]==-1){
k[m]=j;
–x;
}
}
}
// ans is printing k[j] + 1; in a loop from 0 <= j < n, j++
Somebody plz tell me the problem with this answer.i am getting wrong answer.i tried everything
http://www.codechef.com/viewsolution/7068018
Somebody plz tell me the problem with this answer.i am getting wrong answer.i tried everything CodeChef: Practical coding for everyone
My soln can anybody clarify the testcase it will fail, my code is here nDTg7t - Online C++0x Compiler & Debugging Tool - Ideone.com
thank you in advance
P.S. i just need a test case on which it fails.
https://www.codechef.com/viewsolution/14414054
can someone tell what is wrong with my code i am using the simple algorithm for switching the no. if a[i] == i
i am still betting wrong answer
Hi , i don’t know if anyone has done this question in this way or not ,but here is my solution :
https://www.codechef.com/viewsolution/19279294
I have just continuously assigned each voter to the candidates in the same order 0,1,…n-1 , and if the voter and the candidate turn out to be same, i have matched them with the next one .In this way ,what happens is there are only two possibilities either one of them is left with self voting or no one . if only one of them is left(say x) , we can easily just find a voter(say a) who didn’t vote x and voted y and change the array in this way :- x voted a, and a voted y. in this way , the remaining vote of a is used up and everything else remains in the same order .
oh, thats cool I also once used max flow in tc for Div 2 level 2 problem
yes me too… it is much cleaner
Yes, I know this problem but forgot its name. Thanks!
I felt somewhat bad after seeing somewhat uglier in heading, when your solution description starts.
I edited it. Thanks