Problem : https://www.codechef.com/COOK107B/problems/SLUSH

#include <bits/stdc++.h>

using namespace std;

int main()

{

long long t;

cin >> t;

while(t–){

long long n, m;

cin >> n >> m;

long long *c = new long long[m+1];

long long d[1000005];

long long f[1000005];

long long b[1000005];

```
map <long long, long long> drinksLeft;
for(long long i = 1; i <= m; i++){
long long j;
cin >> j;
c[i] = j;
drinksLeft[i] = j;
}
for(long long i = 0; i < n; i++){
cin >> d[i] >> f[i] >> b[i];
}
long long ans = 0;
long long *v = new long long[n];
for(long long i = 0; i < n; i++){
if(drinksLeft[d[i]] > 0){
ans += f[i];
v[i] = d[i];
drinksLeft[d[i]]--;
}
}
// for(long long i = 0; i < n; i++)
// cout << v[i] << " ";
// cout << "\n";
map <long long, long long> drinksLeft2;
map <long long, long long> :: iterator it;
for(long long i = 1; i <= m; i++){
if(drinksLeft[i] > 0)
drinksLeft2[i] = drinksLeft[i];
}
it = drinksLeft2.begin();
for(long long i = 0; i < n; i++){
if(v[i] == 0){
ans += b[i];
v[i] = it->first;
it->second--;
if(it->second == 0)
it++;
}
}
cout << ans << "\n";
for(long long i = 0; i < n; i++)
cout << v[i] << " ";
cout << "\n";
}
```

}