hdu--5281

Source: Internet
Author: User

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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.