地址  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. ubuntu忘记密码,用root修改Ubuntu密码

    今天突发奇想,想改一下ubuntu的用户名,仅仅修改了/etc/passwd中的用户名. 改完后没有用命令修改密码,直接reboot了. 结果悲剧了,登不进去了. 赶紧百度一下,结果发现,本宝宝看不懂 ...

  2. 16经典的SPI Flash的扇区擦除flash_se功能

    一设计功能 对SPI_flash进行扇区擦除,分为写指令和扇区擦除两个时序部分. 二设计知识点 我简单理解flash,第一它是掉电不丢失数据的存储器,第二它每次写入新数据前首先得擦除数据,分为扇区擦除 ...

  3. AD2019(Altium designer)常用快捷键,使用技巧

    测量工具 测量距离:Ctrl+M, 删除测量结果:shift+C, 退出测量:多次右键 设置栅格 G或Ctrl+G 3D查看 按住shift键,再按住鼠标右键移动鼠标,即可在任意角度查看PCB的3D效 ...

  4. 数据库MySql的学习(1)--基本操作

    转自 博客园-hoojo-http://www.cnblogs.com/hoojo/archive/2011/06/20/2085390.html 一.数据库简单介绍 1. 按照数据库的发展时间顺序, ...

  5. SpringMvc中函数的返回值是什么?

    返回值可以有很多类型,有String, ModelAndView.ModelAndView类把视图和数据都合并的一起的,但一般用String比较好.

  6. 哪一个 bash 内置命令能够进行数学运算?

    bash shell 的内置命令 let 可以进行整型数的数学运算. #! /bin/bash - - let c=a+b - -

  7. TCP(三)

    1.三次握手 置位概念:根据TCP的包头字段,存在3个重要的标识ACK.SYN.FIN ACK:表示验证字段 SYN:位数置1,表示建立TCP连接 FIN:位数置1,表示断开TCP连接 三次握手过程说 ...

  8. (stm32f103学习总结)—can总线

    参考:CAN总线的位时序与参数设置 CAN总线位同步 1 CAN总线介绍 CAN 是Controller Area Network 的缩写,中文意思是控制器局域网 络,是ISO国际标准化的串行通信协议 ...

  9. python学习笔记(四)——面向对象编程

    python 支持面向过程编程和面向对象编程. 传统面向过程编程,也叫函数式编程,通过我们的需求设计成一个一个的函数来完成,对一些小规模程序来说面向过程确实简单方便不少.而随着互联网的发展,对于一些大 ...

  10. C# Coding Conventions, Coding Standards & Best Practices

    C# Coding Conventions, Coding Standards & Best Practices Cui, Chikun Overview Introduction This ...