codeforces-462b Appleman and Card Game

Source: Internet
Author: User

It's a simple question.

Sort letters from a number to a small order and then get the most from the problem algorithm

But note that the data type declares money to be a long long

1#include <iostream>2#include <stdio.h>3#include <string.h>4#include <algorithm>5 using namespacestd;6 7 8 intnum[ +];9 Long Longmoney[ +];//because although N is to 10^5 but the operations that have money and money multiplied are stored in the same location, it's super.Ten intN, K; One  A BOOLcmpintAintb) - { -     returnA >b; the } - intMain () - { -     Doublesum =0; +Freopen ("In.txt","R", stdin); -      while(~SCANF ("%d%d", &n, &k)) +     { A GetChar (); atsum =0; -memset (NUM,0,sizeof(num)); -          for(inti =0; I < n; i++) -         { -             Chartemp; -scanf"%c", &temp); innum[temp-'A']++; -         } toSort (num, num+ -, CMP); +          for(inti =0; I < -; i++) -         { theMoney[i] =min (num[i], k); *K-=Num[i]; $             if(k <=0) Break;Panax Notoginseng         } -          for(inti =0; I < -; i++) the         { +sum+= money[i]*Money[i]; A         } theprintf"%.0lf\n", sum); +     } -     return 0; $  $}

codeforces-462b Appleman and Card Game

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.