forked from ntalfer/codingame
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathdocteur_who_le_cadeau.cpp
82 lines (67 loc) · 1.24 KB
/
docteur_who_le_cadeau.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
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
// Read inputs from stdin. Write outputs to stdout.
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
using namespace std;
class Ood
{
public:
Ood(long b)
{
budget = b;
participation = 0;
ruined = (budget == 0);
}
void add_p(long* price)
{
if(!ruined)
{
participation++;
(*price)--;
ruined = (budget == participation);
}
}
long budget;
long participation;
bool ruined;
};
bool sort_by_budget(Ood first, Ood second)
{
return first.budget < second.budget;
}
bool sort_by_participation(Ood first, Ood second)
{
return first.participation < second.participation;
}
int main()
{
long n, c;
cin >> n;
cin >> c;
vector<Ood> oods;
long max_b = 0;
for(long i=0; i<n; i++) {
long b;
cin >> b;
Ood ood(b);
max_b += b;
oods.push_back(ood);
}
if(max_b < c) {
cout << "IMPOSSIBLE" << endl;
return 0;
}
sort(oods.begin(), oods.end(), sort_by_budget);
long price = c;
while(price > 0) {
for(int i=0; i<n and price>0; i++) {
oods[i].add_p(&price);
}
}
sort(oods.begin(), oods.end(), sort_by_participation);
for(int i=0; i<n; i++) {
cout << oods[i].participation << endl;
}
return 0;
}