hihcoder:补提交卡

1051 : 补提交卡

时间限制: 2000ms
单点时限: 1000ms
内存限制: 256MB

描述

小Ho给自己定了一个宏伟的目标:连续100天每天坚持在hihoCoder上提交一个程序。100天过去了,小Ho查看自己的提交记录发现有N天因为贪玩忘记提交了。于是小Ho软磨硬泡、强忍着小Hi鄙视的眼神从小Hi那里要来M张"补提交卡"。每张"补提交卡"都可以补回一天的提交,将原本没有提交程序的一天变成有提交程序的一天。小Ho想知道通过利用这M张补提交卡,可以使自己的"最长连续提交天数"最多变成多少天。

输入

第一行是一个整数T(1 <= T <= 10),代表测试数据的组数。

每个测试数据第一行是2个整数N和M(0 <= N, M <= 100)。第二行包含N个整数a1, a2, ... aN(1 <= a1 < a2 < ... < aN <= 100),表示第a1, a2, ...  aN天小Ho没有提交程序。

输出

对于每组数据,输出通过使用补提交卡小Ho的最长连续提交天数最多变成多少。

样例输入
3  
5 1  
34 77 82 83 84  
5 2  
10 30 55 56 90  
5 10  

10 30 55 56 90

分析:

若想要找到最长连续的提交数,必定可以知道提交卡的使用肯定是连续的,分开使用只会肯定不能得到最优值

题目的意思就是找到连续间隔m的差值

import java.util.*;
import java.io.*;


public class Main{
	static Scanner cin ;
	public static void main(String[] args)throws Exception{
		cin = new Scanner(System.in);
		//cin = new Scanner(new FileInputStream("in.txt"));
		int cases = cin.nextInt();
		while((cases--) != 0){
			int n = cin.nextInt();
			int m = cin.nextInt();
			if(n == 0){
			    System.out.println(100);
			    continue;
			}
			int[] point = new int[n];
			int ans = 0;
			for(int i = 0; i < n; ++i){
				point[i] = cin.nextInt();
//				System.out.print(point[i] + " ");
			}// System.out.println();	
			
			if(n <= m){
				ans = 100;
			}
			else{
				ans = point[m] - 1;
				for(int i = m + 1; i < n; ++i){
					if(ans < point[i] - point[i - m - 1]) ans = point[i] - point[i - m - 1] - 1;	
				}				
				if(ans < 100 - point[n - m]) ans = 100 - point[n - m];
				
			}
			System.out.println(ans);
		}
	}
}



评论 3
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值