Problem C. ICPC Giveaways
Time Limit:20 Sec
Memory limit:256 MB
Topic Connection
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 is delivered completely to T He organizers. For example the organizers ordered items of 4 different types, and what is delivered is 7, 6, 8, 9 from each type res Pectively. The organizers decided to form is bags anyway, but they has to abide by 2 rules. All formed bags should has exactly the same items, and no bag should contain 2 items of the same type (either 1 or 0). Knowing that each item have an amusement value (for sure an MP3 Player are much more amusing than a Sim Card), the organizer S decided to get the max possible total amusement. The total amusement are the amusement value of a single bag multiplied by the number of bags. Note that is not every contestant should receive a bag. The AMUsEment value of each item type was calculated using this equation: (ixi) mod C where I am an integer that represents the IT EM type, and C is a value that would be given as an input. Please help the ICPC organizers to determine what the maximum total amusement are.
Input
T is the number of test cases. For each test case there would be 3 integers m,n and C, where M was 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
Test instructions
Ask you to prepare the bag, everything in each bag requires exactly the same, and then ask you what is the highest value, value = Bag Price * The number of bags can be prepared
The following:
Sort, and then O (n) sweep it all over again ~
Code
#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>typedefLong Longll;using namespacestd;//freopen ("d.in", "R", stdin);//freopen ("D.out", "w", stdout);#defineSspeed ios_base::sync_with_stdio (0); Cin.tie (0)#defineTest Freopen ("Test.txt", "R", stdin)Const intmaxn=202501;#defineMoD 1000000007#defineEPS 1e-9Const intinf=0x3f3f3f3f;Constll infll =0x3f3f3f3f3f3f3f3fll;inline ll Read () {ll x=0, f=1;CharCh=GetChar (); while(ch<'0'|| Ch>'9'){if(ch=='-') f=-1; ch=GetChar ();} while(ch>='0'&&ch<='9') {x=x*Ten+ch-'0'; ch=GetChar ();} returnx*F;}//*************************************************************************************structnode{ll x, Y,}; ll M,n,c;BOOLCMP (node A,node b) {if(a.x==b.x)returnA.y>b.y; returnA.x>b.x;} Node a[11000];intMain () {intt=read (); for(intcas=1; cas<=t;cas++) {m=read (), N=read (), c=read (); Memset (A,0,sizeof(a)); for(intI=1; i<=n;i++) A[i].y= (i*i)%C; for(intI=1; i<=m;i++) {ll x=read (); a[x].x++; } sort (A+1, a+n+1, CMP); ll ans=0; ll Sum=0; for(intI=1; i<=n;i++) { if(a[i].x==0) 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 Sort