-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathAMR_and_Music.cpp
More file actions
48 lines (39 loc) · 1.12 KB
/
AMR_and_Music.cpp
File metadata and controls
48 lines (39 loc) · 1.12 KB
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
// he has n instruments and each ith one take ai days to be learned
// he dedicates k days to learn max possible musical insturments
// we also have to print the index of musical instrument used
typedef long long ll;
#include <bits/stdc++.h>
using namespace std;
int main()
{
ll n , k;
cin >> n >> k;
vector<ll> learn_in(n);
for(ll i = 0; i < n; i++){
cin >> learn_in[i];
}
// Create a vector of pairs where each pair is (days required, original index)
vector<pair<ll, ll>> indices_map(n);
for (ll i = 0; i < n; i++) {
indices_map[i] = {learn_in[i], i};
}
// Sort by days required
sort(indices_map.begin(), indices_map.end());
ll instruments = 0, days = 0;
vector<ll> learnt;
for (const auto entry : indices_map) {
if (days + entry.first <= k) {
days += entry.first;
learnt.push_back(entry.second + 1); // store the original index
instruments++;
}
else {
break;
}
}
// Output the results
cout << instruments << endl;
for (ll i : learnt) {
cout << i << " ";
}
}