CSES - Aalto Competitive Programming 2024 - wk12 Homework - Results
Submission details
Task:Missing Coin Sum
Sender:laluj
Submission time:2024-11-28 15:30:48 +0200
Language:C++ (C++17)
Status:READY
Result:100
Feedback
groupverdictscore
#1ACCEPTED100
Test results
testverdicttime
#1ACCEPTED0.00 sdetails
#2ACCEPTED0.00 sdetails
#3ACCEPTED0.00 sdetails
#4ACCEPTED0.05 sdetails
#5ACCEPTED0.11 sdetails
#6ACCEPTED0.08 sdetails
#7ACCEPTED0.00 sdetails
#8ACCEPTED0.05 sdetails
#9ACCEPTED0.00 sdetails

Compiler report

input/code.cpp: In function 'long long int smallest_unfeasable_subsum(std::vector<long long int>&)':
input/code.cpp:25:23: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<long long int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   25 |     for (int i = 0; i < arr.size(); i++) {
      |                     ~~^~~~~~~~~~~~

Code

#include <bits/stdc++.h>

using namespace std;

#define debug(...) Debug(#__VA_ARGS__, __VA_ARGS__);
template <typename... Args>
void Debug(const char* names, Args&&... args) {
   std::cerr << names << " = ";
   ((std::cerr << args << ", "), ...) << "\b\b " << std::endl;
}
#define ll long long
#define ull unsigned long long
#define vi vector<int>

// Function to find the maximum sum which we cannot
// construct using given coins
ll smallest_unfeasable_subsum(vector<ll>& arr)
{
    // Variable to store the maximum value of the next coin
    ll X = 1LL;

    // Sort the coins in ascending order of their values
    sort(arr.begin(), arr.end());

    for (int i = 0; i < arr.size(); i++) {
        // If the current coin's value is greater than X,
        // then X is the answer
        if (arr[i] > X) {
            return X;
        }
        // If current coin's value is less than or equal to
        // X, then we can update X as X + arr[i]
        X += arr[i];
    }
    return X;
}

int main()
{
    int n;
    cin >> n;
    vector<ll> x(n);
    for (int i = 0; i < n; ++i) cin >> x[i];

    cout << smallest_unfeasable_subsum(x) << endl;
}

Test details

Test 1

Verdict: ACCEPTED

input
4
2 1 4 3

correct output
11

user output
11

Test 2

Verdict: ACCEPTED

input
4
2 2 2 2

correct output
1

user output
1

Test 3

Verdict: ACCEPTED

input
6
1 9 9 1 2 2

correct output
7

user output
7

Test 4

Verdict: ACCEPTED

input
200000
38 62 12 96 82 18 48 47 22 3 6...

correct output
10114269

user output
10114269

Test 5

Verdict: ACCEPTED

input
200000
321076699 332784673 745614086 ...

correct output
1

user output
1

Test 6

Verdict: ACCEPTED

input
200000
1 136292223 60613622 935902310...

correct output
5069547

user output
5069547

Test 7

Verdict: ACCEPTED

input
60
1 2 4 8 16 32 64 128 256 512 1...

correct output
31073741824

user output
31073741824

Test 8

Verdict: ACCEPTED

input
100000
1 2 4 8 16 32 64 128 256 512 1...

correct output
53672058814464

user output
53672058814464

Test 9

Verdict: ACCEPTED

input
10
1 1 1 1 1 1 1 1 2 7

correct output
18

user output
18