problem tags:greedy,implementions
题目:有一只鲨鱼,它有几排牙齿,吃罗非鱼为生,吃一只罗非鱼用一排牙齿,每排牙齿都有忍耐度,当忍耐度不可为负数
input: the first lines is 3 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.
output:
In the first line output the maximum amount of crucians that Valerie can consume for dinner.
#include <iostream>
#include<vector>
using namespace std ;
int a[10001];
int main(int argc, const char * argv[])
{
int n,m,k,r,c;
int sum=0;
cin>>n>>m>>k;
memset(a, 10000, sizeof(a));
for (int i=1; i<=n; i++)
{
cin>>r>>c;
if (c<a[r])
{
a[r]=c;
}
}
for (int i=1; i<=m; i++)
{
sum=sum+a[i];
}
if (sum>k)
{
sum=k;
}
cout<<sum;
return 0;
}