-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathSolution.cc
68 lines (60 loc) · 1.46 KB
/
Solution.cc
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
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
#define __STDC_FORMAT_MACROS
#include <inttypes.h>
#include <math.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <algorithm>
#include <list>
#include <map>
#include <set>
#include <stack>
#include <string>
#include <vector>
using namespace std;
#define VAR(V,init) __typeof(init) V=(init)
#define FOREACH(I,C) for(VAR(I,(C).begin());I!=(C).end();I++)
#define FOR(I, S, E) for(__typeof(S) I=(S); I < (E); ++I)
void readInt64(int64_t *v) {
scanf("%"SCNd64, v);
}
void printInt64(int64_t v) {
printf("%"PRId64, v);
}
struct InstrumentCmp {
bool operator()(const pair<int, int> &a, const pair<int, int> &b) {
if (a.first == b.first) {
return a.second < b.second;
} else {
return a.first < b.first;
}
}
};
int main(int argc, char *argv[]) {
int n, k;
scanf("%d %d", &n, &k);
vector<pair<int, int> > instrumentsByDay;
FOR (i, 1, n+1) {
int d;
scanf("%d", &d);
instrumentsByDay.push_back(make_pair(d, i));
}
sort(instrumentsByDay.begin(), instrumentsByDay.end(), InstrumentCmp());
int ans = 0;
vector<int> instrumentIds;
FOREACH (item, instrumentsByDay) {
k -= item->first;
if (k >= 0) {
ans++;
instrumentIds.push_back(item->second);
}
}
printf("%d\n", ans);
FOREACH (i, instrumentIds) {
printf("%d ", *i);
}
if (ans > 0) {
printf("\n");
}
return 0;
}