[1208] Luo Gu mixing milk

Title Description

Since the dairy industry profit margins are low, so the lower raw material (milk) price becomes very important. Marry help to find the optimal dairy milk procurement program.

Marry dairy purchases milk from the hands of a number of dairy farmers, dairy farmers and every dairy product processing enterprises to provide the price is different. In addition, as per cow a day out only a fixed quantity of milk, dairy farmers can provide the number of milk per day is certain. Marry a day can be purchased from the hands of dairy farmers to an integer number less than or equal to the maximum production of dairy milk.

Marry given the demand for dairy milk, and milk yield per unit price and provide dairy farmers every day. Calculate the minimum cost required to purchase sufficient quantities of milk.

Note: All dairy farmers is greater than the total daily demand Marry dairy industry.

Input and output formats

Input formats:

 

Line 1 of two values: N, (0 <= N <= 2,000,000) is the total number of required milk; M, (0 <= M <= 5,000) is the number of milk farmers.

2 through M + 1 rows: two integers each line: Pi and Ai.

Pi (0 <= Pi <= 1,000) milk farmers monovalent i.

Ai (0 <= Ai <= 2,000,000) is the number of farmers selling milk one day i Marry milk manufacturing company.

 

Output formats:

 

A single line containing a single integer representing Marry milk manufacturing companies get the minimum cost of milk you want.

 

Sample input and output

Input Sample # 1:  Copy
100 5
5 20
9 40
3 10
8 80
6 30
Output Sample # 1:  Copy
630

Explanation

Title Translation from NOCOW.

USACO Training Section 1.3

Solution: a sequence structure to discharge it ok

// luogu-judger-enable-o2
#include<cstdio>
#include<iostream>
#include<cmath>
#include<cstdlib>
#include<cstring>
#include<algorithm>
typedef long long ll;
using namespace std;
struct node{
    int x;
    int y;
}a[5005];
int n,m,ans;
bool cmp(node p,node q){
    if(p.x==q.x) return p.y>q.y;
    return p.x<q.x;
} 
int main(){
    scanf("%d %d",&n,&m);
    for(int i=1;i<=m;i++)
        scanf("%d %d",&a[i].x,&a[i].y);
    sort(a+1,a+m+1,cmp);
    int t=1;
    while(n){
        if(a[t].y!=0){
            a[t].y--;
            ans+=a[t].x;
            n--;
        }
        else t++;
    }
    printf("%d",ans);
    return 0;
}

 

Guess you like

Origin www.cnblogs.com/wuhu-JJJ/p/11205920.html