You are not logged in. Please login at www.codechef.com to post your questions!

×

I can't find mistake in mine solution to SnAckDown Chef and voting best friend solution.

here is my code

#include<iostream>



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;
}

asked 24 May '15, 19:56

v4_adi's gravatar image

2★v4_adi
11358
accept rate: 0%

edited 24 May '15, 20:00


Your solution gives wrong answer for the test case :
1
5
0 0 2 1 2

Your code gives output : 3 4 5 3 5

Clearly, this is wrong since the 5th chef cannot vote himself.

link

answered 24 May '15, 21:22

snk967's gravatar image

4★snk967
1841110
accept rate: 9%

edited 24 May '15, 21:25

Your code will fail with the below test case: 1 7 2 1 1 0 0 0 3

link

answered 24 May '15, 21:28

sumpahpemuda's gravatar image

2★sumpahpemuda
611
accept rate: 66%

toggle preview
Preview

Follow this question

By Email:

Once you sign in you will be able to subscribe for any updates here

By RSS:

Answers

Answers and Comments

Markdown Basics

  • *italic* or _italic_
  • **bold** or __bold__
  • link:[text](http://url.com/ "title")
  • image?![alt text](/path/img.jpg "title")
  • numbered list: 1. Foo 2. Bar
  • to add a line break simply add two spaces to where you would like the new line to be.
  • basic HTML tags are also supported
  • mathemetical formulas in Latex between $ symbol

Question tags:

×42
×37

question asked: 24 May '15, 19:56

question was seen: 889 times

last updated: 24 May '15, 21:28