-
Notifications
You must be signed in to change notification settings - Fork 23
Expand file tree
/
Copy path1015.cpp
More file actions
83 lines (83 loc) · 1.73 KB
/
1015.cpp
File metadata and controls
83 lines (83 loc) · 1.73 KB
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
83
#include<iostream>
#include<cmath>
using namespace std;
int n,m,a[250],b[250],ans[30][1000][30],v[250],s[250],mem[30][1000];
bool t[250];
int main()
{
int i,j,k,l,tests=0;
while(cin>>n>>m)
{
tests++;
if(n==0&&m==0)return 0;
for(i=1;i<=n;i++)
{
cin>>a[i]>>b[i];
v[i]=a[i]-b[i];
s[i]=a[i]+b[i];
}
for(i=0;i<=m;i++)
for(j=0;j<1000;j++)
mem[i][j]=-1;
for(i=1;i<=m;i++)
{
if(i==1)
{
for(j=1;j<=n;j++)
if(s[j]>mem[1][v[j]+500])
{
mem[1][v[j]+500]=s[j];
ans[1][v[j]+500][1]=j;
}
}
else
{
for(j=500-20*i;j<=500+20*i;j++)
{
if(mem[i-1][j]!=-1)
{
for(k=1;k<=n;k++)
t[k]=0;
for(k=1;k<i;k++)
t[ans[i-1][j][k]]=1;
for(k=1;k<=n;k++)
if(!t[k]&&mem[i-1][j]+s[k]>mem[i][j+v[k]])
{
mem[i][j+v[k]]=mem[i-1][j]+s[k];
for(l=1;l<i;l++)
ans[i][j+v[k]][l]=ans[i-1][j][l];
ans[i][j+v[k]][i]=k;
}
}
}
}
}
int s1=0,s2=0;
for(i=0;i<=20*m;i++)
if(mem[m][500+i]!=-1||mem[m][500-i]!=-1)
{
if(mem[m][500-i]>mem[m][500+i])l=500-i;
else l=500+i;
for(j=1;j<=m;j++)
{
s1+=(v[ans[m][l][j]]+s[ans[m][l][j]])/2;
s2+=(s[ans[m][l][j]]-v[ans[m][l][j]])/2;
}
for(j=1;j<=m;j++)
for(k=j+1;k<=m;k++)
if(ans[m][l][j]>ans[m][l][k])
{
ans[m][l][j]^=ans[m][l][k];
ans[m][l][k]^=ans[m][l][j];
ans[m][l][j]^=ans[m][l][k];
}
cout<<"Jury #"<<tests<<"\n";
cout<<"Best jury has value "<<s1<<" for prosecution and value "<<s2<<" for defence:\n";
for(j=1;j<=m;j++)
cout<<" "<<ans[m][l][j];
cout<<endl<<endl;
break;
}
}
return 0;
}