HLJU 1220: AC100天 (枚舉),hljuac100

來源:互聯網
上載者:User

HLJU 1220: AC100天 (枚舉),hljuac100

1220: AC100天Time Limit: 1 Sec  Memory Limit: 128 MB
Submit: 89  Solved: 12
[Submit][Status][Web Board]Description

迪迪給自己定了一個宏偉的目標:連續100天每天堅持AC一道題目。100天過去了,迪迪查看自己的AC記錄發現有N天因為貪玩忘記AC了。於是迪迪軟磨硬泡、強忍著田田鄙視的眼神從田田那裡要來M張"補AC卡"。每張"補AC卡"都可以補回一天的AC,將原本沒有AC的一天變成有AC的一天。迪迪想知道通過利用這M張補AC卡,可以使自己的"最長連續AC天數"最多變成多少天。

Input

輸入包含多組範例。

每個測試資料第一行是2個整數N和M(0 <= N, M <= 100)。第二行包含N個整數a1, a2, ... aN(1 <= a1 < a2 < ... < aN <= 100),表示第a1, a2, ... aN天沒有AC。

Output

對於每組資料,輸出通過使用補AC卡的最長連續AC天數最多變成多少。

Sample Input
5 134 77 82 83 845 210 30 55 56 90
Sample Output
7659
HINT

題中姓名純屬虛構,如有雷同,純屬巧合!

Source

tyh




解析:水題一道,仔細考慮清楚每種特殊情況即可。



AC代碼:

#include <bits/stdc++.h>using namespace std;int a[102];int main(){    #ifdef sxk        freopen("in.txt", "r", stdin);    #endif //sxk    int n, m;    while(~scanf("%d%d", &n, &m)){        for(int i=1; i<=n; i++) scanf("%d", &a[i]);        if(m >= n){ printf("%d\n", 100); continue; }        int ans = 0;        a[0] = 0;        a[n+1] = 101;        for(int i=1; i<=n+1; i++){            int foo = a[min(m+i, n+1)] - 1 - a[i-1];            ans = max(ans, foo);        }        printf("%d\n", ans);    }    return 0;}



聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.