-
Notifications
You must be signed in to change notification settings - Fork 15
Expand file tree
/
Copy paththe-gift.cpp
More file actions
33 lines (29 loc) · 748 Bytes
/
the-gift.cpp
File metadata and controls
33 lines (29 loc) · 748 Bytes
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
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
using namespace std;
int main()
{
int N, C, total_budget(0);
int average;
int l_return;
cin >> N; cin.ignore();
cin >> C; cin.ignore();
vector<int> budgets(N, 0);
for (int i = 0; i < N; i++) { cin >> budgets[i]; cin.ignore(); total_budget += budgets[i]; }
sort( budgets.begin(), budgets.end() );
if ( total_budget < C ) cout << "IMPOSSIBLE" << endl;
else
{
int i = 0;
for ( auto ood : budgets )
{
average = C / (N - i);
l_return = (ood >= average) ? average : ood;
cout << l_return << endl;
C -= l_return;
i++;
}
}
}