A. What is for dinner?
time limit per test2 seconds
memory limit per test256 megabytes
inputstandard input
outputstandard output
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.
Input
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.
Output
In the first line output the maximum amount of crucians that Valerie can consume for dinner.
Examples
inputCopy
4 3 18
2 3
1 2
3 6
2 3
output
11
inputCopy
2 2 13
1 13
2 12
output
13
Readforces!
题意:有一条鲨鱼,有很多排牙齿,每一排牙齿上有几颗牙。一共有K条鲫鱼,每吃一条鱼就会将一排牙齿的耐久度-1。如果发现有牙齿的耐久度到0的时候,该排牙齿就不可以再继续使用了。
#include <iostream>
#include <stdio.h>
#include <math.h>
#include <string.h>
#include <algorithm>
using namespace std;
int a[1005];
int cmp(int a,int b){
return a>b;}
int main()
{
int n,m,k;
scanf("%d%d%d",&n,&m,&k);
memset(a,-1,sizeof a);int tmp;int x;
for(int i=1;i<=n;i++)
{
scanf("%d",&tmp);
scanf("%d",&x);
if(a[tmp]!=-1)
a[tmp]=min(a[tmp],x);
else
a[tmp]=x;
}
sort(a,a+1004,cmp);
int sum=0;
for(int i=0;i<=1004;i++) if(a[i]!=-1) sum+=a[i];
printf("%d\n",min(sum,k));
return 0;
}