Codechef LECANDY

Problem Statement: Link

The following are my solutions to the problem statement.

C++

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
#include <iostream>
#include <vector>
#include <string>

using namespace std;

int main() {
    int T, N;
    unsigned long int C, C2, temp;
    cin >> T;
    vector<string> arr(T);

    for(int i=0; i < T; i++){
        cin >> N >> C;
        C2 = 0;
        for (int j=0; j < N; j++){
            cin >> temp;
            C2 += temp;
        }
        if (C2 > C)
            arr[i] = "No";
        else
            arr[i] = "Yes";
    }

    for(auto& i: arr)
        cout << i << endl;

    return 0;
}

Python

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
def possible(N,C):
    C_wish = sum(map(int, input().split()))
    if C_wish > C:
        return 'No'
    else:
        return 'Yes'
 

T = int(input())
ANS = []

for _ in range(T):
    N, C = map(int, input().split())
    ANS.append(possible(N,C))
    
for an in ANS:
    print(an)
Load Comments?