forked from daiwb/Algorithm
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path152.cpp
More file actions
53 lines (49 loc) · 967 Bytes
/
152.cpp
File metadata and controls
53 lines (49 loc) · 967 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
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
//ac
#include <iostream>
#include <cmath>
#include <cstdio>
#include <vector>
using namespace std;
int main() {
int n;
scanf("%d", &n);
int sum = 0;
vector<int> a(n + 1, 0);
for (int i = 0; i < n; ++i) {
scanf("%d", &a[i]);
sum += a[i];
}
vector<int> up(n + 1, 0);
vector<int> lo(n + 1, 0);
for (int i = n - 1; i >= 0; --i) {
int res = (int)((double)a[i] * 100 / sum);
if (a[i] * 100 % sum == 0) {
up[i] = up[i + 1] + res;
lo[i] = lo[i + 1] + res;
} else {
up[i] = up[i + 1] + res + 1;
lo[i] = lo[i + 1] + res;
}
}
if (up[0] < 100 || lo[0] > 100) {
printf("No solution");
return 0;
}
int now = 0;
vector<int> answer(n);
for (int i = 0; i < n; ++i) {
answer[i] = a[i] * 100 / sum;
if (a[i] * 100 % sum != 0) {
if (now + answer[i] + up[i + 1] < 100) {
answer[i] += 1;
}
}
now += answer[i];
}
for (int i = 0; i < n; ++i) {
if (i) printf(" ");
printf("%d", answer[i]);
}
printf("\n");
return 0;
}