CF33A.What is for dinner?

普及-

通过率:0%

时间限制:2.00s

内存限制:256MB

AC君温馨提醒

该题目为【codeforces】题库的题目,您提交的代码将被提交至codeforces进行远程评测,并由ACGO抓取测评结果后进行展示。由于远程测评的测评机由其他平台提供,我们无法保证该服务的稳定性,若提交后无反应,请等待一段时间后再进行重试。

题目描述

In one little known, but very beautiful country called Waterland, lives a lovely shark Valerie. Like all the sharks, she has several rows of teeth, and feeds on crucians. One of Valerie's distinguishing features is that while eating one crucian she uses only one row of her teeth, the rest of the teeth are "relaxing".

For a long time our heroine had been searching the sea for crucians, but a great misfortune happened. Her teeth started to ache, and she had to see the local dentist, lobster Ashot. As a professional, Ashot quickly relieved Valerie from her toothache. Moreover, he managed to determine the cause of Valerie's developing caries (for what he was later nicknamed Cap).

It turned that Valerie eats too many crucians. To help Valerie avoid further reoccurrence of toothache, Ashot found for each Valerie's tooth its residual viability. Residual viability of a tooth is a value equal to the amount of crucians that Valerie can eat with this tooth. Every time Valerie eats a crucian, viability of all the teeth used for it will decrease by one. When the viability of at least one tooth becomes negative, the shark will have to see the dentist again.

Unhappy, Valerie came back home, where a portion of crucians was waiting for her. For sure, the shark couldn't say no to her favourite meal, but she had no desire to go back to the dentist. That's why she decided to eat the maximum amount of crucians from the portion but so that the viability of no tooth becomes negative.

As Valerie is not good at mathematics, she asked you to help her to find out the total amount of crucians that she can consume for dinner.

We should remind you that while eating one crucian Valerie uses exactly one row of teeth and the viability of each tooth from this row decreases by one.

在某个鲜为人知却极为美丽的国家——水之国(Waterland)中,住着一条可爱的鲨鱼瓦莱丽(Valerie)。和所有鲨鱼一样,她长有多排牙齿,并以鲫鱼为食。瓦莱丽的一个显著特点是:她在吃一条鲫鱼时,仅使用其中一排牙齿,其余牙齿则处于“休息”状态。

长期以来,我们的女主角一直在海中搜寻鲫鱼,然而一场巨大的不幸降临了——她的牙齿开始疼痛,不得不去拜访当地牙医、龙虾阿朔特(Ashot)。作为一名专业牙医,阿朔特迅速缓解了瓦莱丽的牙痛;更进一步,他还查明了瓦莱丽蛀牙发生的原因(因此他后来被戏称为“盖帽者”(Cap))。

原来,瓦莱丽吃了太多鲫鱼!为帮助瓦莱丽避免牙痛再度发作,阿朔特为瓦莱丽的每一颗牙齿测定了其剩余活性值(residual viability)。一颗牙齿的剩余活性值,等于瓦莱丽还能用这颗牙齿吃掉的鲫鱼数量。每当瓦莱丽吃掉一条鲫鱼,该鲫鱼所用的那一排牙齿中的每一颗牙齿的活性值均减少 1。一旦任意一颗牙齿的活性值变为负数,这条鲨鱼就不得不再次去看牙医。

心情低落的瓦莱丽回到了家中,那里已为她准备好了一份鲫鱼。毫无疑问,鲨鱼无法拒绝自己最钟爱的食物;但她又实在不愿再跑一趟牙医诊所。因此,她决定从这份鲫鱼中尽可能多地吃掉一些,但要确保没有任何一颗牙齿的活性值变为负数。

由于瓦莱丽不擅长数学,她请你帮她算出:她今晚最多能吃掉多少条鲫鱼?

需要再次强调:瓦莱丽在吃一条鲫鱼时,恰好使用一排牙齿,且该排中每一颗牙齿的活性值均减少 1。

输入格式

The first line contains three integers n, m, k (1 ≤ m ≤ n ≤ 1000, 0 ≤ k ≤ 106) — total amount of Valerie's teeth, amount of tooth rows and amount of crucians in Valerie's portion for dinner. Then follow n lines, each containing two integers: r (1 ≤ r ≤ m) — index of the row, where belongs the corresponding tooth, and c (0 ≤ c ≤ 106) — its residual viability.

It's guaranteed that each tooth row has positive amount of teeth.

第一行包含三个整数 nn、mm、kk(1 ≤ m ≤ n ≤ 10001 ≤ m ≤ n ≤ 1000,0 ≤ k ≤ 1060 ≤ k ≤ 10^6)—— 分别表示瓦莱丽牙齿的总数、牙弓的数量,以及瓦莱丽晚餐中鲫鱼的数量。接下来是 nn 行,每行包含两个整数:rr(1 ≤ r ≤ m1 ≤ r ≤ m)—— 表示该牙齿所属的牙弓编号;cc(0 ≤ c ≤ 1060 ≤ c ≤ 10^6)—— 表示该牙齿的剩余活力值。

保证每个牙弓均含有至少一颗牙齿。

输出格式

In the first line output the maximum amount of crucians that Valerie can consume for dinner.

第一行输出瓦莱丽晚餐最多能吃的鲫鱼数量。

输入输出样例

  • 输入#1

    4 3 18
    2 3
    1 2
    3 6
    2 3

    输出#1

    11
  • 输入#2

    2 2 13
    1 13
    2 12

    输出#2

    13

输入解题思路,AI测评打分。不知道怎么写?

首页