Quantcast
Channel: CodeChef Discuss - latest questions
Viewing all articles
Browse latest Browse all 39796

Paying Up, answer is wrong

$
0
0

All kinds of test cases are giving the right output but when i submit it , it always shows "wrong answer"

can anyone tell me whats wrong??

#include <algorithm>
#include <iostream>
#include <cstdio>
using namespace std;

#define gc getchar_unlocked

void scanint(int &x)

{
    register int c=gc();
    x=0;
    for(;(c<48||c>57);
    c=gc());
    for(;c>47&&c<58;c=gc()) 
    {
        x=(x<<1)+(x<<3)+c- 48;
    }
}

int main()

{
    int t,n,m,sum,j,i;

     int notes[20];
     scanint(t);
     while(t--)
    {
        scanint(n);
        scanint(m);

        for(i=0;i<n;i++)
        {
            scanint(notes[i]);

        }
        sort(notes,notes+n);

        for(i=0;i<n;i++)
        {   sum=notes[i];
            for(j=0;j<n;j++)
            {
                if(sum<m)
               {
                 sum=sum+notes[j];
                 if(sum>m)
                 sum=sum-notes[j];
               }
            }

            for(j=0;j<i;j++)
            {
                if(sum<m)
                sum=sum+notes[j];
                if(sum>m)
                 sum=sum-notes[j];

            }
            if (sum==m)
            break;
        }
        if(sum==m)
        printf("Yes\n");
        else
        printf("No\n");
    }
    return 0;
}

Viewing all articles
Browse latest Browse all 39796

Latest Images

Trending Articles



Latest Images

<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>