zoukankan      html  css  js  c++  java
  • Bayan 20122013 Elimination Round (ACM ICPC Rules, English statements) A. Old Peykan

    A. Old Peykan
    time limit per test
    2 seconds
    memory limit per test
    256 megabytes
    input
    standard input
    output
    standard output

    There are n cities in the country where the Old Peykan lives. These cities are located on a straight line, we'll denote them from left to right as c1, c2, ..., cn. The Old Peykan wants to travel from city c1 to cn using roads. There are (n - 1) one way roads, the i-th road goes from city ci to city ci + 1 and is di kilometers long.

    The Old Peykan travels 1 kilometer in 1 hour and consumes 1 liter of fuel during this time.

    Each city ci (except for the last city cn) has a supply of si liters of fuel which immediately transfers to the Old Peykan if it passes the city or stays in it. This supply refreshes instantly k hours after it transfers. The Old Peykan can stay in a city for a while and fill its fuel tank many times.

    Initially (at time zero) the Old Peykan is at city c1 and s1 liters of fuel is transferred to it's empty tank from c1's supply. The Old Peykan's fuel tank capacity is unlimited. Old Peykan can not continue its travel if its tank is emptied strictly between two cities.

    Find the minimum time the Old Peykan needs to reach city cn.

    Input

    The first line of the input contains two space-separated integers m and k (1 ≤ m, k ≤ 1000). The value m specifies the number of roads between cities which is equal to n - 1.

    The next line contains m space-separated integers d1, d2, ..., dm (1 ≤ di ≤ 1000) and the following line contains m space-separated integers s1, s2, ..., sm (1 ≤ si ≤ 1000).

    Output

    In the only line of the output print a single integer — the minimum time required for The Old Peykan to reach city cn from city c1.

    Sample test(s)
    Input
    4 6
    
    1 2 5 2
    2 3 3 4
    Output
    10
    Input
    2 3
    
    5 6
    5 5
    Output
    14
    Note

    In the second sample above, the Old Peykan stays in c1 for 3 hours.

    贪心的感觉,看懂题意就简单了。

    View Code
     1 #include<stdio.h>
     2 #define maxn 1010
     3 int d[maxn],s[maxn];
     4 int main()
     5 {
     6     int n,k;
     7     int max,sum,ans;
     8     while(~scanf("%d%d",&n,&k))
     9     {
    10         max=0;
    11         sum=0;
    12         ans=0;
    13         for(int i=0;i<n;i++)
    14         {
    15             scanf("%d",&d[i]);
    16             ans+=d[i];
    17         }
    18         for(int i=0;i<n;i++)
    19         {
    20             scanf("%d",&s[i]);
    21         }
    22         int count=0;
    23         for(int i=0;i<n;i++)
    24         {
    25             if(max<s[i]) max=s[i];
    26             if(s[i]+sum>=d[i]) sum=(sum+s[i]-d[i]);
    27             else 
    28             {
    29                 do
    30                 {
    31                     sum+=max;
    32                     
    33                     count++;
    34                 }while(sum+s[i]<d[i]);
    35                 sum=sum+s[i]-d[i];
    36                 
    37                 
    38             }
    39             
    40         }
    41         ans+=(count*k);
    42         printf("%d\n",ans);
    43     }
    44 }

    http://codeforces.com/contest/241/problem/A

  • 相关阅读:
    用jquery判断当前显示器的分辨率,加载不同CSS
    [置顶] Android SDK下载和更新失败的解决方法!!!
    [置顶] 最全的Android开发开发资料
    [置顶] Android入门教程导入现有Android工程
    [置顶] 用Android访问本地站点(localhost,10.0.2.2)
    [置顶] Android入门教程Android工程目录结构介绍
    [置顶] 解决Android解析图片的OOM问题
    [置顶] Android入门教程环境搭建
    [置顶] Android 中的拿来主义(编译,反编译,AXMLPrinter2,smali,baksmali)
    Windows 8 平板电脑体验及思考
  • 原文地址:https://www.cnblogs.com/1114250779boke/p/2750621.html
Copyright © 2011-2022 走看看