It is my great honour to introduce myself to you here. My name is Aloysius Benjy Cobweb Dartagnan Egbert Felix Gaspar Humbert Ignatius Jayden Kasper Leroy Maximilian. As a storyteller, today I decide to tell you and others a story about the hero Huriyyah, and the monsters.

Once upon a time, citizens in the city were suffering from nn powerful monsters. They ate small children who went out alone and even killed innocent persons. Before the hero appeared, the apprehension had overwhelmed the people for several decades. For the good of these unfortunate citizens, Huriyyah set off to the forest which was the main lair of monsters and fought with nn fierce and cruel monsters. The health point of the ii-th monster was HP_iHPi​, and its attack value was ATK_iATKi​.

They fought in a cave through a turn-based battle. During each second, the hero Huriyyah was attacked by monsters at first, and the damage was the sum of attack values of all alive monsters. Then he selected a monster and attacked it. The monster would suffer the damage of kk (its health point would decrease by kk) which was the times of attacks it had been came under. That is to say, for each monster, the damage of the first time that Huriyyah attacked it was 11, and the damage of Huriyyah's second attack to this monster was 22, the third time to this monster was 33, and so on. If at some time, the health point of a monster was less than or equal to zero, it died. The hero won if all monsters were killed.

Now, my smart audience, can you calculate the minimum amount of total damages our hero should suffer before he won the battle?

Input

The input contains several test cases, and the first line is a positive integer TT indicating the number of test cases which is up to 10^3103.

For each test case, the first line contains an integers n (1 \le n \le 10^5)n(1≤n≤105) which is the number of monsters. The ii-th line of the following nn lines contains two integers HP_iHPi​ and ATK_i (1 \le HP_i, ATK_i \le 10^5)ATKi​(1≤HPi​,ATKi​≤105) which describe a monster.

We guarantee that the sum of nn in all test cases is up to 10^6106.

Output

For each test case, output a line containing Case #x: y, where xx is the test case number starting from 11, and yy is the minimum amount of total damages the hero should suffer.

输出时每行末尾的多余空格,不影响答案正确性

样例输入复制

2
3
1 1
2 2
3 3
3
3 1
2 2
1 3

样例输出复制

Case #1: 19
Case #2: 14

这个题是一个贪心题,一开始使用的攻击力/血量作为贪心准则,然后样例能过,就在我要交的时候,队友说不同的HP杀死用的时间是一样的,所以这个题,确实是没读太懂题,在读了一遍题目,然后1A过了,题意举个生动的例子,时下最火的自走棋,对方上了一群大汉,现在你的德莱文畏畏缩缩的缩在角落,敌人的血量与攻击力不同,你攻击别人一下,然后所有人都打你一下,现在让你求怎样杀死所有人使得自己掉血最少。

#include<iostream>
#include<queue>
#include<algorithm>
#include<set>
#include<cmath>
#include<vector>
#include<map>
#include<stack>
#include<bitset>
#include<cstdio>
#include<cstring>
//---------------------------------Sexy operation--------------------------// #define cini(n) scanf("%d",&n)
#define cinl(n) scanf("%lld",&n)
#define cinc(n) scanf("%c",&n)
#define cins(s) scanf("%s",s)
#define coui(n) printf("%d",n)
#define couc(n) printf("%c",n)
#define coul(n) printf("%lld",n)
#define debug(n) printf("%d_________________________________\n",n);
#define speed ios_base::sync_with_stdio(0)
#define file freopen("input.txt","r",stdin);freopen("output.txt","w",stdout)
//-------------------------------Actual option------------------------------//
#define rep(i,a,n) for(int i=a;i<=n;i++)
#define per(i,n,a) for(int i=n;i>=a;i--)
#define Swap(a,b) a^=b^=a^=b
#define Max(a,b) (a>b?a:b)
#define Min(a,b) a<b?a:b
#define mem(n,x) memset(n,x,sizeof(n))
#define mp(a,b) make_pair(a,b)
#define pb(n) push_back(n)
#define dis(a,b,c,d) ((double)sqrt((a-c)*(a-c)+(b-d)*(b-d)))
//--------------------------------constant----------------------------------// #define INF 0x3f3f3f3f
#define esp 1e-9
#define PI acos(-1)
using namespace std;
typedef pair<int,int>PII;
typedef pair<string,int>PSI;
typedef long long ll;
//___________________________Dividing Line__________________________________/
struct PPP
{
int HP;
int GJ;
int Time;
}a[100010];
int num(int a)
{
int sum=0,cnt=1;
while(1)
{
sum++;
a=a-cnt++;
if(a<=0) return sum;
}
}
bool cmp(PPP a,PPP b)
{
return a.Time*b.GJ<b.Time*a.GJ;
}
int main()
{
int t,k=0;
scanf("%d",&t);
while(k++<t)
{
int n,i;
scanf("%d",&n);
for(i=0;i<n;i++)
{
cini(a[i].HP),cini(a[i].GJ);
a[i].Time=num(a[i].HP);
}
sort(a,a+n,cmp);
ll sum=0,cnt=0;
for(i=0;i<n;i++)
{
cnt+=a[i].Time;
sum+=cnt*a[i].GJ;
}
printf("Case #%d: %lld\n",k,sum); }
return 0;
}

2019 ICPC 银川网络赛 H. Fight Against Monsters的更多相关文章

  1. 2019 ICPC 银川网络赛 D. Take Your Seat (疯子坐飞机问题)

    Duha decided to have a trip to Singapore by plane. The airplane had nn seats numbered from 11 to nn, ...

  2. 2019 ICPC 银川网络赛 F-Moving On (卡Cache)

    Firdaws and Fatinah are living in a country with nn cities, numbered from 11 to nn. Each city has a ...

  3. 2019 ICPC 南昌网络赛

    2019 ICPC 南昌网络赛 比赛时间:2019.9.8 比赛链接:The 2019 Asia Nanchang First Round Online Programming Contest 总结 ...

  4. 2019 ICPC上海网络赛 A 题 Lightning Routing I (动态维护树的直径)

    题目: 给定一棵树, 带边权. 现在有2种操作: 1.修改第i条边的权值. 2.询问u到其他一个任意点的最大距离是多少. 题解: 树的直径可以通过两次 dfs() 的方法求得.换句话说,到任意点最远的 ...

  5. 2019 ICPC 沈阳网络赛 J. Ghh Matin

    Problem Similar to the strange ability of Martin (the hero of Martin Martin), Ghh will random occurr ...

  6. 2019 ICPC 南京网络赛 F Greedy Sequence

    You're given a permutation aa of length nn (1 \le n \le 10^51≤n≤105). For each i \in [1,n]i∈[1,n], c ...

  7. 2019 ICPC 南昌网络赛I:Yukino With Subinterval(CDQ分治)

    Yukino With Subinterval Yukino has an array a_1, a_2 \cdots a_na1,a2⋯*a**n*. As a tsundere girl, Yuk ...

  8. 2019 ICPC南昌网络赛 B题

    英雄灭火问题忽略了一点丫 一个超级源点的事情,需要考虑周全丫 2 #include<cstdio> #include<cstring> #include<queue> ...

  9. 2019 ICPC 徐州网络赛 B.so easy (并查集)

    计蒜客链接:https://nanti.jisuanke.com/t/41384 题目大意:给定n个数,从1到n排列,其中有q次操作,操作(1) 删除一个数字 // 操作(2)求这个数字之后第一个没有 ...

随机推荐

  1. Matlab入门(二)

    数据类型 1.整形 有符号 1 字节整数 -27 - 27-1 int8() 有符号 2 字节整数 -215 - 215-1 int16() 有符号 4 字节整数 -231 - 231-1 int32 ...

  2. 深入理解智能指针之shared_ptr(一)

    本文基于C++标准库源码分析shared_ptr,旨在搞清楚shared_ptr是什么,线程安全性等,目标能够安全的使用智能指针. (一)shared_ptr是一个类. 首先可以确定的是shared_ ...

  3. 超过百万的StackOverflow Flutter 问题

    老孟导读:今天分享StackOverflow上高访问量的20大问题,这些问题给我一种特别熟悉的感觉,我想你一定或多或少的遇到过,有的问题在stackoverflow上有几十万的阅读量,说明很多人都遇到 ...

  4. 数据结构和算法(Golang实现)(16)常见数据结构-字典

    字典 我们翻阅书籍时,很多时候都要查找目录,然后定位到我们要的页数,比如我们查找某个英文单词时,会从英语字典里查看单词表目录,然后定位到词的那一页. 计算机中,也有这种需求. 一.字典 字典是存储键值 ...

  5. Github star 1.7k 的项目源码解析

    先拜读源码,最后总结,以及其他实现思路.如有错误,欢迎指正! 项目介绍 名称:Darkmode.js 功能:给你的网站添加暗色模式 项目链接:https://github.com/sandoche/D ...

  6. Threejs从入门到入门

    前言threejs官网:https://threejs.org/ github各个版本:https://github.com/mrdoob/three.js/tags 版本更迭很快,我用的时候还是r9 ...

  7. 浅谈Vector

    浅谈Vector 在之前的文章中,我们已经说过线程不安全的ArrayList和LinkedList,今天我们来讲讲一个线程安全的列表容器,他就是Vector,他的底层和ArrayList一样使用数组来 ...

  8. Daily Scrum 12/17/2015

    Process: Zhaoyang:完成了相册图片的异步加载. Yandong&Dong:   对Azure的体系架构进行学习和相应的编程. Fuchen:   对Oxford计划中的NLP接 ...

  9. Obtain The String CodeForces - 1295C binary_search+思维

    妈耶,,,被B题卡到哭,C题一发就过了... 字符串问题.首先用vector记录每个字符出现的位置,然后对字符串t的每个字符,用二分查找函数查找,注意用upper_bound查找,对于字符i,首先用变 ...

  10. Go gRPC进阶-go-grpc-middleware使用(八)

    前言 上篇介绍了gRPC中TLS认证和自定义方法认证,最后还简单介绍了gRPC拦截器的使用.gRPC自身只能设置一个拦截器,所有逻辑都写一起会比较乱.本篇简单介绍go-grpc-middleware的 ...