-
Notifications
You must be signed in to change notification settings - Fork 0
/
greater
65 lines (57 loc) · 1.09 KB
/
greater
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
/**
* HDU-1171-Big Event in HDU
* 30/12/15 19:17:38
* xuchen
**/
/**
* dp
* */
#include <iostream>
#include <cstdio>
#include <cmath>
#include <vector>
#include <string.h>
#include <algorithm>
#include <stdlib.h>
#include <queue>
#include <stack>
using namespace std;
const int N = 150005;
bool dp[N];
int num[55];
int val[55];
int main()
{
int n;
while (scanf("%d", &n) && n>-1)
{
int sum = 0;
memset(dp, 0, sizeof(dp));
for(int i=1; i<=n; i++)
{
scanf("%d%d", &val[i], &num[i]);
sum += val[i]*num[i];
}
int half = sum/2;
dp[0] = true;
for(int i=1; i<=n; i++)
{
for(int j=0; j<num[i]; j++)
{
for(int k=half; k>=val[i]; k--)
{
if(dp[k-val[i]])
dp[k] = true;
}
}
}
int ans = half;
for(; ans>=0; ans--)
{
if(dp[ans])
break;
}
printf("%d %d\n", sum-ans, ans);
}
return 0;
}