地址  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;
}

Educational Codeforces Round 108 (Div. 2), C map套vector存储的更多相关文章

  1. 组合数学题 Codeforces Round #108 (Div. 2) C. Pocket Book

    题目传送门 /* 题意:每一次任选i,j行字符串进行任意长度前缀交换,然后不断重复这个过程,问在过程中,第一行字符串不同的个数 组合数学题:每一列不同的字母都有可能到第一行,所以每列的可能值相乘取模就 ...

  2. Codeforces Round #108 (Div. 2)

    Codeforces Round #108 (Div. 2) C. Pocket Book 题意 给定\(N(N \le 100)\)个字符串,每个字符串长为\(M(M \le 100)\). 每次选 ...

  3. Educational Codeforces Round 84 (Div. 2)

    Educational Codeforces Round 84 (Div. 2) 读题读题读题+脑筋急转弯 = =. A. Sum of Odd Integers 奇奇为奇,奇偶为偶,所以n,k奇偶性 ...

  4. Educational Codeforces Round 62 Div. 2

    突然发现上一场edu忘记写了( A:签到. #include<iostream> #include<cstdio> #include<cmath> #include ...

  5. Educational Codeforces Round 47 (Div 2) (A~G)

    目录 Codeforces 1009 A.Game Shopping B.Minimum Ternary String C.Annoying Present D.Relatively Prime Gr ...

  6. Educational Codeforces Round 46 (Div 2) (A~G)

    目录 Codeforces 1000 A.Codehorses T-shirts B.Light It Up C.Covered Points Count(差分) D.Yet Another Prob ...

  7. Educational Codeforces Round 58 Div. 2 自闭记

    明明多个几秒就能场上AK了.自闭. A:签到. #include<iostream> #include<cstdio> #include<cmath> #inclu ...

  8. Educational Codeforces Round 45 (Div 2) (A~G)

    目录 Codeforces 990 A.Commentary Boxes B.Micro-World C.Bracket Sequences Concatenation Problem D.Graph ...

  9. Educational Codeforces Round 85 (Div. 2)

    题目链接:https://codeforces.com/contest/1334 A. Level Statistics 题意 一个关卡有玩家的尝试次数和通关次数,按时间顺序给出一个玩家 $n$ 个时 ...

随机推荐

  1. 解决Hadoop集群hdfs无法启动DataNode的问题

    问题描述: 在hadoop启动hdfs的之后,使用jps命令查看运行情况时发现hdfs的DataNode并没有打开. 笔者出现此情况前曾使用hdfs namenode -format格式化了hdfs ...

  2. eclipse启动指定jvm的版本

    参阅:https://www.eclipse.org/forums/index.php/t/1105435/ https://wiki.eclipse.org/Eclipse.ini#-vm_valu ...

  3. Springboot添加静态资源映射addResourceHandlers,可实现url访问

    @Configuration //public class WebMvcConfiger extends WebMvcConfigurerAdapter { public class WebMvcCo ...

  4. Dubbo telnet 命令能做什么?

    dubbo 服务发布之后,我们可以利用 telnet 命令进行调试.管理. Dubbo2.0.5 以上版本服务提供端口支持 telnet 命令 连接服务 telnet localhost 20880 ...

  5. NOW()和 CURRENT_DATE()有什么区别?

    NOW()命令用于显示当前年份,月份,日期,小时,分钟和秒. CURRENT_DATE()仅显示当前年份,月份和日期.

  6. MyBatis Plus 2.3 个人笔记-01-代码生成器

    sb_mybatis_puls2.3 <?xml version="1.0" encoding="UTF-8"?> <project xmln ...

  7. Effective Java —— 用私有构造器或枚举类型强化单例属性

    本文参考 本篇文章参考自<Effective Java>第三版第三条"Enforce the singleton property with a private construc ...

  8. UP9616移动电源快充案例

    第一版的UP9616快充(地址在此 ),从选料到线路板的布局走线都还算不错,实现了当初定下的设计目标,但也有一点小小的遗憾,就是在输出滤波电容这里有点随便了,为了弥补这个遗憾,秉着工程师的" ...

  9. 无单位数字和行高 —— 别说你懂CSS相对单位

    前段时间试译了Keith J.Grant的CSS好书<CSS in Depth>,其中的第二章<Working with relative units>,书中对relative ...

  10. 记一次曲折的CVE-2018-1270复现分析

    前言 前两天接到朋友对某个授权目标的漏扫结果,也算是初次接触到这个漏洞,就想着顺手分析一下复现一下,因为分析这个漏洞的文章也比较少,所以刚开始比较迷,进度也比较慢. 漏洞复现 使用vulhub搭建环境 ...