10-18 noip increase group simulation competition (codecomb) T2 greedy

Source: Internet
Author: User

T2: Find min: always find the smallest one until a [I]-x + 1 is smaller than 0, and so on;

The same is true if you want to find Max. You can find the largest one until the next largest one is bigger than the previous one;

This simulation can use priority_queue;

#include <cstdio>#include <cstring>#include <algorithm>#include <iostream>#include <queue>using namespace std;const int maxn=1000001;int n,m;int a[maxn];long long minx,maxx;priority_queue<int> q;int main(){    scanf("%d%d",&n,&m);    for(int i=1;i<=n;i++){    scanf("%d",&a[i]);    q.push(a[i]);    }    sort(a+1,a+n+1);    int temp=1;for(int i=1;i<=m;i++){    int t=q.top();    q.pop();    maxx+=t;    q.push(t-1);    while(!a[temp]) temp++;    minx+=a[temp];    a[temp]--;    }    cout<<maxx<<" "<<minx;return 0;}

 

10-18 noip increase group simulation competition (codecomb) T2 greedy

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.