Test instructions: Give n guns, M monsters, each gun can destroy 1 monsters, and gain energy = Gun's attack-the monster's defense Force. How to kill to get the most energy? (No need to kill the light)
Idea: The monster with the greatest attack power will obviously get the maximum energy. If every gun is shot to kill a monster that doesn't have 1 energy, it's tantamount to throwing away all the guns.
1 //#pragma COMMENT (linker, "/stack:102400000,102400000")2#include <iostream>3#include <stdio.h>4#include <string.h>5#include <vector>6#include <stack>7#include <algorithm>8#include <map>9#include <bits/stdc++.h>Ten #defineLL Long Long One #definePII pair<int,int> A #defineINF 0x7f7f7f7f - using namespacestd; - Const intn=100000+5; the intA[n], b[n]; - - intMain () - { + //freopen ("Input.txt", "R", stdin); - intt, N, M; +Cin>>T; A while(t--) at { -scanf"%d%d", &n, &m); - - for(intI=0; i<n; i++) scanf ("%d",&a[i]); - for(intI=0; i<m; i++) scanf ("%d",&b[i]); - inSort (A, A +n); -Sort (b, + +m); to intbb=0, aa=n-1; +LL ans=0; - while(aa>=0&& bb<m && a[aa]>B[BB]) the { *ans+=a[aa]-B[BB]; $bb++;Panax Notoginsengaa--; - } theprintf"%lld\n", ans); + } A the + return 0; -}
AC Code
HDU Senior ' s Gun (water problem)