题目链接: http://acm.zju.edu.cn/onlinejudge/showProblem.do?problemCode=3757
#include<cstdio>
#include<cstring>
#include<iostream>
#include<algorithm>
#include<vector>
#include<string>
#include<map>
#include<set>
#include<cmath>
#include<sstream>
#include<queue> #define MAXN 1050
#define PI acos(-1.0)
#define REP(i,n) for(int i=0; i<n; i++)
#define FOR(i,s,t) for(int i=s; i<=t; i++)
#define show(x) { cerr<<">>>"<<#x<<" = "<<x<<endl; }
#define showtwo(x,y) { cerr<<">>>"<<#x<<"="<<x<<" "<<#y<<" = "<<y<<endl; }
using namespace std; int n,m;
int a[MAXN],ans[];
bool used[MAXN*]; int main()
{
//freopen("E:\\acm\\input.txt","r",stdin);
while(cin>>n>>m)
{
memset(used,,sizeof(used));
a[] = ans[] = ans[] = ;
FOR(i,,n) scanf("%d",&a[i]);
sort(a+,a+n+); int cur = ,i = ;
while(m--) //去第i个球
{
while(used[a[i]]) i++; int p,q,p_largest ,q_sum;
bool target_in_p,target_in_q,cue_in_q;
q_sum = p_largest = ;
target_in_p = target_in_q = cue_in_q = ;
cin>>p;
FOR(j,,p)
{
int num; cin>>num;
p_largest = max(p_largest,num);
if(num == a[i]) target_in_p = true;
}
cin>>q;
FOR(j,,q)
{
int num; cin>>num;
if(num == a[i]) target_in_q = true;
if(num == ) cue_in_q = true;
else used[num] = true;
q_sum += num;
} bool foul = false;
if(p == )
ans[cur^] += a[i],foul = true;
else if( !cue_in_q && (!target_in_p || p > ))
ans[cur^] += p_largest,foul = true;
else if(cue_in_q)
ans[cur^] += p_largest,foul = true; if(!foul && target_in_q)
{
ans[cur] += q_sum;
cur ^= ;
}
else if((target_in_q && foul) || ( !target_in_q && q-cue_in_q > ) )
{
ans[cur^] += q_sum;
}
cur ^= ;
}
printf("%d : %d\n",ans[],ans[]);
}
}