-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathD.cpp
51 lines (50 loc) · 1.18 KB
/
D.cpp
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
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
#include <bits/stdc++.h>
using namespace std;
const int maxn = 7e4 + 10;
bitset <maxn> dp, done;
pair <int, int> a[maxn];
int b[maxn], inside[maxn];
int first[maxn];
int main() {
int n, s;
cin >> n >> s;
for(int i = 1; i <= n; i++) {
cin >> a[i].first;
a[i].second = i;
b[i] = a[i].first;
}
sort(a + 1, a + n + 1);
dp[0] = 1;
done[0] = 1;
for(int i = 1; i < n; i++) {
dp |= dp << a[i].first;
done = dp ^ done;
for(int j = done._Find_first(); j < done.size(); j = done._Find_next(j)) {
first[j] = i;
}
done = dp;
}
int cur = s - a[n].first;
if(cur < 0 || !dp[cur]) {
cout << -1 << endl;
exit(0);
}
vector <int> take ({n});
while(cur > 0) {
take.push_back(first[cur]);
cur -= a[first[cur]].first;
}
take.push_back(0);
sort(take.begin(), take.end());
for(int i = 1; i < take.size(); i++) {
for(int j = take[i - 1] + 1; j < take[i]; j++) {
inside[a[j + 1].second] = a[j].second;
}
}
for(int i = 1; i <= n; i++) {
cout << b[i] - b[inside[i]] << ' ';
if(inside[i]) cout << 1 << ' ' << inside[i] << endl;
else cout << 0 << endl;
}
return 0;
}