zoukankan      html  css  js  c++  java
  • 10-18 noip提高组模拟赛(codecomb)T2贪心

    T2:找min:一直找最小的那个,直到a[i]-x+1小于0,就找次小的,以此类推;

    求max,也是一样的,一直到最大的那个,直到次大的比之前最大的大,就找次大的;

    这个模拟,可以用上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;
    }
    
  • 相关阅读:
    mplayer命令行模式下的使用方法
    CentOS安装wireshark
    CentOS查看系统信息
    测试理论1
    单例模式
    接口测试
    rabbitmq
    redis数据库
    时间模块
    charles抓取数据
  • 原文地址:https://www.cnblogs.com/polebug/p/4034822.html
Copyright © 2011-2022 走看看