CSES - Datatähti 2017 alku - Results
Submission details
Task:Kolikot
Sender:comp
Submission time:2016-10-08 00:52:30 +0300
Language:C++
Status:COMPILE ERROR

Compiler report

input/code.cpp: In function 'int main()':
input/code.cpp:34:5: error: 'sort' is not a member of 'std'
     std::sort(coins.begin(), coins.end());
     ^

Code

#include <iostream>
#include <set>
#include <vector>

int min_sum;

bool hasnt_skipped(std::set<int> &sums) {
    int previous = *(sums.begin());
    int highest = *(sums.rbegin());
    while (previous < highest) {
        if (sums.find(previous + 1) != sums.end()) {
            previous += 1;
            continue;
        } else {
            min_sum = previous + 1;
            return false;
        }
    }
    min_sum = highest + 1;
    return true;
}

int main() {
    int n;
    std::cin >> n;
    std::vector<int> coins;
    
    int x;
    for(int i = 0; i < n; ++i) {
        std::cin >> x;
        coins.push_back(x);
    }
    
    std::sort(coins.begin(), coins.end());
    
    std::set<int> sofar;
    std::vector<int> news;
    
    sofar.insert(0);
    
    for(auto c: coins) {
        for(auto s: sofar) {
            news.push_back(c + s);
        }
        for(auto nw: news) {
            sofar.insert(nw);
        }
        news.clear();
        
        bool skip_test;
        skip_test = hasnt_skipped(sofar);
        if (skip_test == true) {
            continue;
        } else {
            break;
        }
    }
    
    std::cout << min_sum;
    return 0;
}