zoukankan      html  css  js  c++  java
  • Codeforce 588A

    Duff is addicted to meat! Malek wants to keep her happy for n days. In order to be happy in i-th day, she needs to eat exactly ai kilograms of meat.

    There is a big shop uptown and Malek wants to buy meat for her from there. In i-th day, they sell meat for pi dollars per kilogram. Malek knows all numbers a1, ..., an and p1, ..., pn. In each day, he can buy arbitrary amount of meat, also he can keep some meat he has for the future.

    Malek is a little tired from cooking meat, so he asked for your help. Help him to minimize the total money he spends to keep Duff happy for n days.

    Input

    The first line of input contains integer n (1 ≤ n ≤ 105), the number of days.

    In the next n lines, i-th line contains two integers ai and pi (1 ≤ ai, pi ≤ 100), the amount of meat Duff needs and the cost of meat in that day.

    Output

    Print the minimum money needed to keep Duff happy for n days, in one line.

    Examples
    input
    3
    1 3
    2 2
    3 1
    output
    10
    input
    3
    1 3
    2 1
    3 2
    output
    8
    Note

    In the first sample case: An optimal way would be to buy 1 kg on the first day, 2 kg on the second day and 3 kg on the third day.

    In the second sample case: An optimal way would be to buy 1 kg on the first day and 5 kg (needed meat for the second and third day) on the second day.

     题解:不断更新肉价的最小值

     1 #include <iostream>
     2 #include <algorithm>
     3 #include <cstring>
     4 #include <cstdio>
     5 #include <vector>
     6 #include <cstdlib>
     7 #include <iomanip>
     8 #include <cmath>
     9 #include <ctime>
    10 #include <map>
    11 #include <set>
    12 using namespace std;
    13 #define lowbit(x) (x&(-x))
    14 #define max(x,y) (x>y?x:y)
    15 #define min(x,y) (x<y?x:y)
    16 #define MAX 100000000000000000
    17 #define MOD 1000000007
    18 #define pi acos(-1.0)
    19 #define ei exp(1)
    20 #define PI 3.141592653589793238462
    21 #define INF 0x3f3f3f3f3f
    22 #define mem(a) (memset(a,0,sizeof(a)))
    23 typedef long long ll;
    24 const int N=100005;
    25 const int mod=1e9+7;
    26 int a[N],b[N];
    27 int main()
    28 {
    29     int n;
    30     scanf("%d",&n);
    31     for(int i=0;i<n;i++){
    32         scanf("%d %d",&a[i],&b[i]);
    33     }
    34     ll s=0;
    35     s+=a[0]*b[0];
    36     int t=b[0];
    37     for(int i=1;i<n;i++){
    38         if(b[i]<t) t=b[i];
    39         s+=a[i]*t;
    40     }
    41     printf("%lld
    ",s);
    42     return 0;
    43 }
  • 相关阅读:
    摄像头置顶成品
    opencv鼠标事件
    opencvinpainting图像修复
    opencvdilate膨胀
    opencverode侵蝕
    opencvOTSU大津法—最大类间方差法
    opencvgetStructuringElement结构元素(内核矩阵)
    opencv时间
    IDEA在代码上无错误提示,但是编译时出现error:非法字符
    计算机端口号
  • 原文地址:https://www.cnblogs.com/wydxry/p/7258556.html
Copyright © 2011-2022 走看看