Search
 
SCRIPT & CODE EXAMPLE
 

CPP

Tricky Subset Problem

int isPossible(long long S, long long N, long long X, long long A[])
    {
        // code here
        long long sum = S;
        long long idx = N-1 ;
        for(long long i=0; i<N ;i++)
        {
            A[i]= A[i] + sum;
            sum = sum +  A[i];
            if(A[i] >= X)
            {
                idx=i;
                break;
            }
        }
        while(idx>=0)
        {
            if(X >= A[idx])
            X = X - A[idx];
            idx--;
        }
        if( X==0 || X == S) return 1;
        return 0;
    
    }
Comment

PREVIOUS NEXT
Code Example
Cpp :: find number of 1s in a binary cv::mat image 
Cpp :: cpp practice questions 
Cpp :: vector stop at newline 
Cpp :: convert string to wide string 
Cpp :: Write C++ program that will ask to choose from three cases. 
Cpp :: how to user input in string to open files in c++ 
Cpp :: stp 
Cpp :: C++ (gcc 8.3) sample 
Cpp :: No Index Out of Bound Checking in C++ 
Cpp :: partition in STL using vector 
Cpp :: C:UsersBBCDocumentsc n c++ project8PuzzleSolvemain.c|38|warning: suggest parentheses around assignment used as truth value [-Wparentheses]| 
Cpp :: MPI_Sendrecv 
Cpp :: appdivind c++ stuctures 
Cpp :: ex:Roblox 
Cpp :: void linux java 
Cpp :: how to find total numbe of distinct characters in a string in c 
Cpp :: button creation in C++ GUI 
Cpp :: npm wasm 
Cpp :: constant qualifier c++ "error display" 
Cpp :: cast c++ 
Cpp :: Consider a pair of integers, (a,b). The following operations can be performed on (a,b) in any order, zero or more times: - (a,b) - ( a+b, b ) - (a,b) - ( a, a+b ) 
Cpp :: import matrix from excel to matlab 
Cpp :: online computer graphics compiler c++ 
Cpp :: assignment operator 
Cpp :: C++ area & circumference of a circle 
Cpp :: how to change the type of something in c++ 
Cpp :: function overloading in cpp 
Cpp :: c++ how to skip the last element of vector 
C :: random number between 2 in C 
C :: arma 3 get group size 
ADD CONTENT
Topic
Content
Source link
Name
5+8 =