• codeforces #326 div 2 A. Duff and Meat(水)


    A. Duff and Meat
    time limit per test
    1 second
    memory limit per test
    256 megabytes
    input
    standard input
    output
    standard output

    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 forn 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.

    Sample test(s)
    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.

    做点水题换换脑子。。。

    浙大月赛题已经做蒙了QAQ

    这题很简单。。

    扫的时候记得更新价钱的最小值就好了。

     1 /*************************************************************************
     2     > File Name: code/cf/#326/A.cpp
     3     > Author: 111qqz
     4     > Email: rkz2013@126.com 
     5     > Created Time: 2015年10月22日 星期四 20时00分33秒
     6  ************************************************************************/
     7 
     8 #include<iostream>
     9 #include<iomanip>
    10 #include<cstdio>
    11 #include<algorithm>
    12 #include<cmath>
    13 #include<cstring>
    14 #include<string>
    15 #include<map>
    16 #include<set>
    17 #include<queue>
    18 #include<vector>
    19 #include<stack>
    20 #include<cctype>
    21                  
    22 #define yn hez111qqz
    23 #define j1 cute111qqz
    24 #define ms(a,x) memset(a,x,sizeof(a))
    25 using namespace std;
    26 const int dx4[4]={1,0,0,-1};
    27 const int dy4[4]={0,-1,1,0};
    28 typedef long long LL;
    29 typedef double DB;
    30 const int inf = 0x3f3f3f3f;
    31 const int N=1E5+7;
    32 int n;
    33 int a[N],p[N];
    34 int main()
    35 {
    36   #ifndef  ONLINE_JUDGE 
    37    freopen("in.txt","r",stdin);
    38   #endif
    39 
    40    scanf("%d",&n);
    41    for ( int i = 0 ;  i < n ; i++) scanf("%d %d",&a[i],&p[i]);
    42    int mi = inf;
    43    int ans = 0 ;
    44    for ( int i = 0 ; i < n ; i++)
    45    {
    46        if (p[i]<mi)
    47        mi = p[i];
    48        
    49        ans += mi*a[i];
    50    }
    51    cout<<ans<<endl;
    52   
    53    
    54  #ifndef ONLINE_JUDGE  
    55   fclose(stdin);
    56   #endif
    57     return 0;
    58 }
    View Code
  • 相关阅读:
    hdu 4107 Gangster 线段树(成段更新)
    hdu 3037 Saving Beans (lucas定理)
    hdu 3944 DP? (Lucas 定理)
    hdu 5038 Grade 水
    ASP.NET Core 配置 MVC
    ASP.NET Core 静态文件
    ASP.NET Core 异常和错误处理
    ASP.NET Core 中间件
    ASP.NET Core 项目配置 ( Startup )
    ASP.NET Core 基本项目目录结构
  • 原文地址:https://www.cnblogs.com/111qqz/p/4902678.html
Copyright © 2020-2023  润新知