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