地址  Problem - C - Codeforces

题目

题意

一个学校有n个人参加比赛,他们分别属于ui队,每个人的能力值为si

当每个队需要1~n个人的时候,这个学校能参加的人的能力值和最大为多少

解析

map<int,vector<int>>存储不会爆

每一队直接处理出队伍人数为1~n时的能力值最大和,这样不会超时,看代码

代码

#include <iostream>
#include <algorithm>
#include <vector>
#include <map> using namespace std; typedef long long LL;
const int N = 2e5+10; int b[N],c[N];
int main()
{
int t;
cin >> t;
while(t --)
{
int n;
scanf("%d", &n);
map<int,vector<LL>> a;//存第二波输入 for(int i = 1; i <= n; i ++) scanf("%d", &b[i]); //存所属队
for(int i = 1; i <= n; i ++){
int x;
scanf("%d", &x);
a[b[i]].push_back(x);
} vector<LL> res(n+1);//存结果
for(auto p1:a)//遍历每一队
{
vector<LL> &p = p1.second;
sort(p.begin(), p.end()); int len = p.size(); for(int i = 1; i < len; ++i)
p[i] += p[i-1]; for(int i = 1; i <= len; i ++)
res[i]+=p[len-1]-((len%i)?p[len%i-1]:0LL);//把这一队的算出来
}
for(int i = 1; i <= n; i ++)
cout << res[i] << ' ';
puts(""); }
return 0;
}

最新文章

  1. hybrid app
  2. 今天说一下where 中 exists 和 in 里面的一些区别
  3. iOS工程适配64-bit经验分享
  4. ext2 源代码解析之 “从路径名到目标结点” (一)
  5. cpu、内存、缓存、硬盘使用率
  6. mysql生成百万级数量测试数据
  7. [Swift]LeetCode540. 有序数组中的单一元素 | Single Element in a Sorted Array
  8. [CQOI2015]网络吞吐量
  9. 14JDBC
  10. RSA key format is not supported
  11. html 腳本
  12. golang学习笔记6 beego项目路由设置
  13. php 建站 多域名配置 自定义重定向
  14. jquery 属性-记住
  15. 编程输出杨辉三角的前10行---多维数组的应用---java实现
  16. AngularJS开发指南:表达式
  17. hbase 学习(十五)缓存机制以及可以利用SSD作为存储的BucketCache
  18. POJ 1118
  19. MP1593 RT8272 ACT4070 制作的DC-DC稳压电源
  20. 经常使用的CSS Hack技术集锦

热门文章

  1. instanceOf与父子类型转换
  2. S7-1200学习记录
  3. Redis数据结构详解(2)-redis中的字典dict
  4. IDEA端口占用的解决方案
  5. 怎么清屏?怎么退出当前命令?怎么执行睡眠?怎么查看当前用户 id?查看指定帮助用什么命令?
  6. springcloud断路器作用?
  7. SpringDataJpa使用审计(Auditing)功能
  8. (6) 结论,摘要与题目_Conclusion, Abstract, and Title【论文写作】
  9. google fonts 国内使用解决方案
  10. android SQLite数据库(转)