[Offer收割]编程练习赛4 register

Ended

Participants:899

Verdict:Accepted
Score:100 / 100
Submitted:2016-08-07 13:09:08

Lang:G++

Edit
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
31
#include <iostream>
#include <set>
#include <vector>
using namespace std;
int proc() {
    int n, x;
    cin >> n >> x;
    
    vector<int> data;
    data.resize(n);
    for (int i = 0; i < n; ++ i) {
        cin >> data[i];
    }
    
    set<int> a, b;
    a.insert(0);
    b.insert(0);
    
    for (int i: data) {
        for (int j: a) {
            b.insert(j + i);
        }
        a = b;
    }
    
    for (int i: a) {
        if (i >= x) return i;
    }
    return -1;
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX