跳到正文

个人记录

CF-321B

marx2012约 2 分钟
原文
文章信息与版本

文章信息

收录
2025年12月12日
更新
2025年12月12日
篇幅
约 2 分钟

版本

  1. v1当前
C++
#include<bits/stdc++.h>
#define ll long long
using namespace std;
ll n,m,str,a[105],cpy[105],atk[105],def[105],cnt1,cnt2,ans1,ans2;
string pos;
bool flag=true;
bool cmp(ll a,ll b){return a>b;}
int main()
{
    ios::sync_with_stdio(0);
    cin.tie(0),cout.tie(0);
	cin>>n>>m;
	for(int i=1;i<=n;i++)
	{
		cin>>pos;
		cin>>str;
		if(pos=="ATK") atk[++cnt1]=str;
		else def[++cnt2]=str;
	}
	for(int i=1;i<=m;i++)
	{
	    cin>>a[i];
	    cpy[i]=a[i];
	}//备份
//	sort(def+1,def+1+cnt2);
//	sort(a+1,a+1+m);
//	for(int i=1;i<=cnt2;i++)
//	{
//		int x=upper_bound(a+1,a+1+m,def[i])-a;
//		if(a[x]<=def[i]){flag=false;break;}
//		a[x]=-1;
//	}
//	if(flag)
//	{
//		sort(atk+1,atk+1+cnt1);
//		for(int i=1;i<=cnt1;i++)
//		{
//			int x=lower_bound(a+1,a+1+m,atk[i])-a;
//			if(a[x]>=atk[i]) ans1+=a[x]-atk[i];
//			else{flag=false;break;}
//			a[x]=-1;
//		}
//	}
//	if(flag) for(int i=1;i<=m;i++) if(a[i]!=-1) ans1+=a[i];
	sort(atk+1,atk+1+cnt1);
	sort(cpy+1,cpy+1+m,cmp);
	for(int i=1;i<=min(m,cnt1);i++) if(cpy[i]>=atk[i]) ans2+=cpy[i]-atk[i],cpy[i]=-1;
    cout<<ans1<<" "<<ans2<<endl;
	cout<<max(ans1,ans2);
	return 0;
}
原文