Ultraviolet A 11292-Dragon of loowater

Source: Internet
Author: User

Question: A dragon has n heads and M brave men. The power of a brave man is greater than the leader's size to defeat him. Each brave man needs an equivalent commission,

Ask how much it costs to kill a dragon.

Analysis: greedy. First, sort the dragons and brave warriors in ascending order. Then, each time you hire the brave ones with the smallest current capacity value, you can kill the dragons.

(If the current brave leads to an unsuitable optimal solution, he will be hired earlier if he has a higher commission than he has previously)

Note: Tianji Horse Racing (⊙ _ ⊙ ).

#include <algorithm>#include <iostream>#include <cstdlib>#include <cstdio>using namespace std;int d[20001];int k[20001];int main(){int n,m;while ( scanf("%d%d",&n,&m) && n+m ) {for ( int i = 0 ; i < n ; ++ i )scanf("%d",&d[i]);for ( int i = 0 ; i < m ; ++ i )scanf("%d",&k[i]);sort( d, d+n );sort( k, k+m );int now = 0,sum = 0,flag = 0;for ( int i = 0 ; i < n ; ++ i ) {while ( now < m && d[i] > k[now] )now ++;if ( now >= m ) {flag = 1; break;}else sum += k[now ++];}if ( flag ) printf("Loowater is doomed!\n");else printf("%d\n",sum);}return 0;}

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.