Educational Codeforces Round 108 (Div. 2), C map套vector存储
2024-10-20 15:31:38
地址 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;
}
最新文章
- hybrid app
- 今天说一下where 中 exists 和 in 里面的一些区别
- iOS工程适配64-bit经验分享
- ext2 源代码解析之 “从路径名到目标结点” (一)
- cpu、内存、缓存、硬盘使用率
- mysql生成百万级数量测试数据
- [Swift]LeetCode540. 有序数组中的单一元素 | Single Element in a Sorted Array
- [CQOI2015]网络吞吐量
- 14JDBC
- RSA key format is not supported
- html 腳本
- golang学习笔记6 beego项目路由设置
- php 建站 多域名配置 自定义重定向
- jquery 属性-记住
- 编程输出杨辉三角的前10行---多维数组的应用---java实现
- AngularJS开发指南:表达式
- hbase 学习(十五)缓存机制以及可以利用SSD作为存储的BucketCache
- POJ 1118
- MP1593 RT8272 ACT4070 制作的DC-DC稳压电源
- 经常使用的CSS Hack技术集锦
热门文章
- instanceOf与父子类型转换
- S7-1200学习记录
- Redis数据结构详解(2)-redis中的字典dict
- IDEA端口占用的解决方案
- 怎么清屏?怎么退出当前命令?怎么执行睡眠?怎么查看当前用户 id?查看指定帮助用什么命令?
- springcloud断路器作用?
- SpringDataJpa使用审计(Auditing)功能
- (6) 结论,摘要与题目_Conclusion, Abstract, and Title【论文写作】
- google fonts 国内使用解决方案
- android SQLite数据库(转)