Problem C. ICPC Giveaways
Time Limit: 20 Sec

Memory Limit: 256 MB

题目连接

http://codeforces.com/gym/100500/attachments

Description

During the preparation for the ICPC contest, the organizers prepare bags full of giveaways for the contestants. Each bag usually contains an MP3 Player, a Sim Card, a USB HUB, a USB Flash Drive, ... etc. A problem happened during the delivery of the components of the bags, so not every component was delivered completely to the organizers. For example the organizers ordered 10 items of 4 different types, and what was delivered was 7, 6, 8, 9 from each type respectively. The organizers decided to form bags anyway, but they have to abide by 2 rules. All formed bags should have exactly the same items, and no bag should contain 2 items of the same type (either 1 or 0). Knowing that each item has an amusement value (for sure an MP3 Player is much more amusing than a Sim Card), the organizers decided to get the max possible total amusement. The total amusement is the amusement value of a single bag multiplied by the number of bags. Note that not every contestant should receive a bag. The amusement value of each item type is calculated using this equation:(i × i) mod C where i is an integer that represents the item type, and C is a value that will be given as an input. Please help the ICPC organizers to determine what the maximum total amusement is.

Input

T is the number of test cases. For each test case there will be 3 integers M,N and C, where M is the number of items, N is the total number of types, and C is as described above then M integer representing the type of each item. 1 ≤ T ≤ 100 1 ≤ M ≤ 10, 000 1 ≤ N ≤ 10, 000 1 ≤ C ≤ 10, 000 1 ≤ itemi ≤ N

Output

For each test case print a single line containing: Case_x:_y x is the case number starting from 1. y is the required answer. Replace the underscores with spaces.

Sample Input

1 10 3 9 1 1 2 2 1 1 2 3 1 2

Sample Output

Case 1: 20

HINT

题意

要求你准备袋子,每个袋子里的东西都要求完全一样,然后问你价值最高为多少,价值=袋子的价格*可以准备的袋子数量

题解

排序,然后O(n)扫一遍就好啦~

代码

#include <cstdio>
#include <cmath>
#include <cstring>
#include <ctime>
#include <iostream>
#include <algorithm>
#include <set>
#include <vector>
#include <sstream>
#include <queue>
#include <typeinfo>
#include <fstream>
#include <map>
#include <stack>
typedef long long ll;
using namespace std;
//freopen("D.in","r",stdin);
//freopen("D.out","w",stdout);
#define sspeed ios_base::sync_with_stdio(0);cin.tie(0)
#define test freopen("test.txt","r",stdin)
const int maxn=;
#define mod 1000000007
#define eps 1e-9
const int inf=0x3f3f3f3f;
const ll infll = 0x3f3f3f3f3f3f3f3fLL;
inline ll read()
{
ll x=,f=;char ch=getchar();
while(ch<''||ch>''){if(ch=='-')f=-;ch=getchar();}
while(ch>=''&&ch<=''){x=x*+ch-'';ch=getchar();}
return x*f;
}
//************************************************************************************* struct node
{
ll x,y;
};
ll m,n,c;
bool cmp(node a,node b)
{
if(a.x==b.x)
return a.y>b.y;
return a.x>b.x;
}
node a[];
int main()
{
int t=read();
for(int cas=;cas<=t;cas++)
{
m=read(),n=read(),c=read();
memset(a,,sizeof(a));
for(int i=;i<=n;i++)
a[i].y=(i*i)%c;
for(int i=;i<=m;i++)
{
ll x=read();
a[x].x++;
}
sort(a+,a+n+,cmp);
ll ans=;
ll sum=;
for(int i=;i<=n;i++)
{
if(a[i].x==)
break;
sum+=a[i].y;
ans=max(ans,a[i].x*sum);
}
printf("Case %d: %lld\n",cas,ans);
}
}

codeforces Gym 100500C C. ICPC Giveaways 排序的更多相关文章

  1. codeforces Gym 100500C D.Hall of Fame 排序

    Hall of Fame Time Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://codeforces.com/gym/100500/attachmen ...

  2. codeforces Gym 100500H H. ICPC Quest 水题

    Problem H. ICPC QuestTime Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://codeforces.com/gym/100500/a ...

  3. Codeforces Gym 101623A - 动态规划

    题目传送门 传送门 题目大意 给定一个长度为$n$的序列,要求划分成最少的段数,然后将这些段排序使得新序列单调不减. 考虑将相邻的相等的数缩成一个数. 假设没有分成了$n$段,考虑最少能够减少多少划分 ...

  4. Codeforces Gym 101252D&&floyd判圈算法学习笔记

    一句话题意:x0=1,xi+1=(Axi+xi%B)%C,如果x序列中存在最早的两个相同的元素,输出第二次出现的位置,若在2e7内无解则输出-1. 题解:都不到100天就AFO了才来学这floyd判圈 ...

  5. Codeforces Gym 101190M Mole Tunnels - 费用流

    题目传送门 传送门 题目大意 $m$只鼹鼠有$n$个巢穴,$n - 1$条长度为$1$的通道将它们连通且第$i(i > 1)$个巢穴与第$\left\lfloor \frac{i}{2}\rig ...

  6. 【Codeforces Gym 100725K】Key Insertion

    Codeforces Gym 100725K 题意:给定一个初始全0的序列,然后给\(n\)个查询,每一次调用\(Insert(L_i,i)\),其中\(Insert(L,K)\)表示在第L位插入K, ...

  7. Codeforces gym 101343 J.Husam and the Broken Present 2【状压dp】

     2017 JUST Programming Contest 2.0 题目链接:Codeforces gym 101343 J.Husam and the Broken Present 2 J. Hu ...

  8. codeforces gym 100553I

    codeforces gym 100553I solution 令a[i]表示位置i的船的编号 研究可以发现,应是从中间开始,往两边跳.... 于是就是一个点往两边的最长下降子序列之和减一 魔改树状数 ...

  9. CodeForces Gym 100213F Counterfeit Money

    CodeForces Gym题目页面传送门 有\(1\)个\(n1\times m1\)的字符矩阵\(a\)和\(1\)个\(n2\times m2\)的字符矩阵\(b\),求\(a,b\)的最大公共 ...

随机推荐

  1. delphi 编译的时候 把Warning去除的方法

    delphi  编译的时候  把Warning去除的方法 在 添加 {$WARNINGS OFF}

  2. 利用ioctl()获取无线速率

    其实对于自己装了网卡驱动的来说,应该从最根本的驱动中获取速率. 但是用ioctl()也可以,其实实现和iwconfig命令相同. 仅仅获取速率这部分: #include <stdio.h> ...

  3. Tour

    题意: 给n个点的坐标,求形成的最短的闭合回路. 分析: 经典问题,dp[i][j]表示有1-i点再由j回到1点的最短距离,i点有两种情况,在去的路径上 dp[i][j]=min(dp[i][j],d ...

  4. 《Python基础教程(第二版)》学习笔记 -> 第八章 异常

    什么是异常 Python用 异常对象(exception object)来表示异常情况.遇到错误后,会引发异常,如果异常对象并未被处理或者捕捉,程序就会用所谓的回溯(Traceback,一种错误信息) ...

  5. ili9341 横屏驱动代码

    void ili9341_Initializtion(void) { u16 i; RCC->APB2ENR|=<<; //使能PORTB时钟 GPIOB->CRH&= ...

  6. 关于SecureCRT的安装和破解问题以及xp系统的串口问题

    今天下午找了几个小时的软件,因为交叉编译环境要搭好,其中SecureCRT还有串口问题要解决,我突然间发现我开始光盘中的SecureCRT坏掉了,在网站上下载SecureCRT,结果要很多的积分,这样 ...

  7. C#相关图书推荐

    C#入门经典(第6版) 作      者 [美] Karli Watson,Jacob Vibe Hammer,Jon D Reid 等 著: 出 版 社 清华大学出版社 出版时间 2014-01-0 ...

  8. vs2012不能打开项目解决办法

    只要卸载这两个不定就能解决问题.

  9. boosting和bagging

    首先来说明一下bootstraps:可以把它认为是一种有放回的抽样方法. bagging:boostraps aggregating(汇总) boosting:Adaboot (Adaptive Bo ...

  10. node-mysql中的连接池代码学习

    node-mysql是一个node.js下的mysql驱动,前段时间在处理连接池的问题上遇到了连接不释放的疑难杂症,虽已解决,但仍需总结经验避免下次重蹈覆辙.下面是node-mysql中的连接池的部分 ...