思路:

贪心。

实现:

 #include <bits/stdc++.h>
using namespace std;
int a[];
int main()
{
int n, m;
while (cin >> n >> m)
{
for (int i = ; i <= n; i++) cin >> a[i];
sort(a + , a + n + );
long long ans = ;
int maxn = a[], cnt = a[] - ;
for (int i = ; i <= n; i++)
{
if (a[i] == a[i - ])
{
if (cnt) { ans += a[i]; cnt--; }
else ans += a[i] - ;
}
else
{
cnt += a[i] - maxn - ;
ans += maxn;
maxn = a[i];
}
}
cout << ans << endl;
}
return ;
}

最新文章

  1. Vue.js学习笔记(1)
  2. 使用scrapy创建工程
  3. RDLC报表打印
  4. ImportError: No module named MySQLdb
  5. 问题解决——WSAAsyncSelect模型 不触发 FD_CLOSE
  6. iOS - MVC 架构模式
  7. Python中的导入
  8. 12_CXF入门
  9. MFC添加自定义消息
  10. SimpleXML 使用详细例子
  11. wpf中数据绑定(Datacontext)的应用
  12. 关于使用mybatis中mapper instrances,通过session另一种操作方式
  13. error LNK1123: 转换到 COFF 期间失败: 文件无效或损坏
  14. 运维面试题之linux编程
  15. C# SemaphoreSlim 实现
  16. Android : 跟我学Binder --- (2) AIDL分析及手动实现
  17. web分页打印
  18. USBDM RS08/HCS08/HCS12/Coldfire V1,2,3,4/DSC/Kinetis Debugger and Programmer -- MC9S08JM16/32/60
  19. tf.transpose函数的用法讲解
  20. 使用zabbix发送邮件的简易设置流程(存档用)

热门文章

  1. eclipse Tomcat 启动报错
  2. MakeFile 文件的使用
  3. MTK USB 子系统
  4. ubuntu 下串口调试工具 minicom安装与配置
  5. leetcode398 and leetcode 382 蓄水池抽样算法
  6. Nginx的安装配置和tomcat负载均衡
  7. 如何在html中引入jsx文件
  8. 64位Win7中7zip无法关联文件的问题
  9. lightoj 1089 【离散化+线段树】
  10. bzoj 2406: 矩阵【二分+有源汇上下界可行流】