zoukankan      html  css  js  c++  java
  • Codeforces Round #226 (Div. 2)A. Bear and Raspberry

     /*
        贪心的找到相邻两项差的最大值,再减去c,结果若是负数答案为0.
    */
    1
    #include <stdio.h> 2 #define maxn 105 3 int num[maxn]; 4 int main() 5 { 6 int n,c; 7 while(~scanf("%d%d",&n,&c)) 8 { 9 int ans = 0; 10 for(int i = 0;i < n;i++) 11 scanf("%d",num+i); 12 for(int i = 0;i < n-1;i++){ 13 int temp = num[i] - num[i+1]; 14 if(temp > ans) 15 ans = temp; 16 } 17 ans -= c; 18 if(ans>=0) 19 printf("%d ",ans); 20 else 21 printf("0 "); 22 } 23 }
  • 相关阅读:
    String类
    Scanner类
    Object类
    接口
    static关键字
    final关键字
    抽象类
    权限修饰符
    方法重写 (Override)
    面向对象思想特征
  • 原文地址:https://www.cnblogs.com/Roly/p/3596603.html
Copyright © 2011-2022 走看看