Official:
Easy to find the final plan must be the strongest attack K gun to eliminate the weakest defense of the K-only monsters, then we on the gun and the monster after the two to distinguish the maximum number of guns can be used, and then enumerate the use of a few guns to update the answer. Complexity of
o(nlOgn)
。
The key is that the strongest elimination of the weakest here, unexpectedly do not come out, small ideas at that time did not think so incredibly search to do, indeed, the time is really a bit of concept also wood has ...
Thought problem said simple also simple, but unexpectedly really do not come out, these several problems have to pay attention to the data range, not long long on the miserable.
#include <iostream> #include <cstring> #include <cstdio> #include <map> #include <cstring > #include <algorithm> #include <vector> #define INF 0x3f3f3f3f3f3f#define Mem (A, B) memset (A,b,sizeof (a) ) using namespace Std;typedef long long ll;typedef unsigned long long llu;const int maxd=100000+10;//--------------------- int a[maxd],b[maxd];ll suma[maxd],sumb[maxd];int N,m;int cnt; void Init () {scanf ("%d%d", &n,&m); suma[0]=sumb[0]=0; for (int i=1; i<=n; ++i) scanf ("%d", &a[i]); for (int i=1; i<=m; ++i) scanf ("%d", &b[i]); Sort (a+1,a+n+1); Sort (b+1,b+m+1); cnt=0; for (int i=1;i<=n;++i) {if (a[i]<b[1]) a[i]=0,++cnt; Suma[i]=suma[i-1]+a[i]; } for (int i=1;i<=m;++i) sumb[i]=sumb[i-1]+b[i];} ll solve () {ll ans=0; for (int k=1;k<=min (n-cnt,m); ++k) Ans=max (ans, (LL) suma[n]-suma[n-k]-(Sumb[k])); return ans;} int main () {freopen ("1.txt", "R", stdin); int Kase; scanf ("%d", &kase); while (kase--) {init (); printf ("%i64d\n", Solve ()); } return 0;}
Copyright NOTICE: This article for Bo Master original article, without Bo Master permission not reproduced.
hdu--5281