Codeforces 33A. What is for dinner?(简单题)

题目链接:http://codeforces.com/contest/33/problem/A

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 nmk (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
input
Copy
4 3 18
2 3
1 2
3 6
2 3
output
Copy
11
input
Copy
2 2 13
1 13
2 12
output
Copy
13


题目大意:鲨鱼要吃小鱼,每次会用一排牙齿去吃鱼,吃一条小鱼会消耗牙齿一点耐久,某一排有一颗牙齿消耗完了耐久值该排就不能再吃了,问最多能吃几条鱼。

数据输入:给你n颗牙齿,分布在m排,总共k条鱼,接下来n排,每排两个数,r,c,该颗牙齿在哪一排,和其耐久值。

题目思路:记录每排牙齿最小耐久值,求和ans,ans=min(ans,k)即可。

代码:

#include<cstdio>
#include<cmath>
#include<cstring>
#include<string>
#include<cstdlib>
#include<algorithm>
#include<iostream>
#include<queue>
#include<stack>
#include<map>

using namespace std;

#define FOU(i,x,y) for(int i=x;i<=y;i++)
#define FOD(i,x,y) for(int i=x;i>=y;i--)
#define MEM(a,val) memset(a,val,sizeof(a))
#define PI acos(-1.0)

const double EXP = 1e-9;
typedef long long ll;
typedef unsigned long long ull;
const int INF = 0x3f3f3f3f;
const ll MINF = 0x3f3f3f3f3f3f3f3f;
const double DINF = 0xffffffffffff;
const int mod = 1e9+7;
const int N = 1e6+5;

int val[1005];

int main()
{
    //freopen("in.txt","r",stdin);
    //freopen("out.txt","w",stdout);
    std::ios::sync_with_stdio(false);
    int n,m,k,r,c;
    cin>>n>>m>>k;
    for(int i=1;i<=n;i++)
        val[i]=INF;
    for(int i=1;i<=n;i++)
    {
        cin>>r>>c;
        val[r]=min(val[r],c);
    }
    int ans=0;
    for(int i=1;i<=n;i++)
    {
        if(val[i]!=INF)
            ans+=val[i];
    }
    cout<<min(ans,k)<<endl;
    return 0;
}

猜你喜欢

转载自blog.csdn.net/baodream/article/details/80286542