-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy patho.cpp
79 lines (66 loc) · 1.14 KB
/
o.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
#include <algorithm>
#include <iostream>
#include <cassert>
#include <climits>
#include <cstdlib>
#include <cstring>
#include <cstdio>
#include <string>
#include <vector>
#include <cmath>
#include <ctime>
#include <queue>
#include <stack>
#include <map>
using namespace std;
#define mp make_pair
#define st first
#define nd second
#define ll long long
#define pll pair<long long, long long>
#define pb push_back
int n, newSum = 1e5;
int roundedW[105], last[100005];
double w[105], sum;
int main()
{
ios_base::sync_with_stdio(false);
cin.tie(NULL);
while (true)
{
cin >> n;
if (!n)
break;
sum = 0;
for (int i = 1; i <= n; i++)
{
cin >> w[i];
sum += w[i];
}
for (int i = 1; i <= n; i++)
roundedW[i] = ceil(w[i] * newSum / sum);
memset(last, 0, sizeof last);
last[0] = -1;
for (int i = 1; i <= n; i++)
for (int j = newSum / 2; j >= 0; j--)
{
if (!last[j])
continue;
last[j + roundedW[i]] = i;
}
for (int i = newSum / 2; i >= 0; i--)
{
if (last[i])
{
while (i)
{
cout << last[i] << ' ';
i = i - roundedW[last[i]];
}
cout << endl;
break;
}
}
}
return 0;
}