Round A 2020 - Kick Start 2020 Workout【二分】

Problem

Tambourine has prepared a fitness program so that she can become more fit! The program is made of N sessions. During the i-th session, Tambourine will exercise for Mi minutes. The number of minutes she exercises in each session are strictly increasing.

 

The difficulty of her fitness program is equal to the maximum difference in the number of minutes between any two consecutive training sessions.

To make her program less difficult, Tambourine has decided to add up to K additional training sessions to her fitness program. She can add these sessions anywhere in her fitness program, and exercise any positive integer number of minutes in each of them. After the additional training session are added, the number of minutes she exercises in each session must still be strictly increasing. What is the minimum difficulty possible?

Input

The first line of the input gives the number of test cases, TT test cases follow. Each test case begins with a line containing the two integers N and K. The second line contains N integers, the i-th of these is Mi, the number of minutes she will exercise in the i-th session.

Output

For each test case, output one line containing Case #x: y, where x is the test case number (starting from 1) and y is the minimum difficulty possible after up to K additional training sessions are added.

Limits

Time limit: 20 seconds per test set.
Memory limit: 1GB.
1 ≤ T ≤ 100.
For at most 10 test cases, 2 ≤ N ≤ 105.
For all other test cases, 2 ≤ N ≤ 300.
1 ≤ Mi ≤ 109.
Mi < Mi+1 for all i.

Test set 1

K = 1.

Test set 2

1 ≤ K ≤ 105.

Samples


Input 1
 

Output 1
 
1
3 1
100 200 230
  
Case #1: 50
  

Input 2
 

Output 2
 
3
5 2
10 13 15 16 17
5 6
9 10 20 26 30
8 3
1 2 3 4 5 6 7 10
  
Case #1: 2
Case #2: 3
Case #3: 1
  
Sample #1

In Case #1: Tambourine can add up to one session. The added sessions are marked in bold: 100 150 200 230. The difficulty is now 50.

 

Sample #2

In Case #1: Tambourine can add up to two sessions. The added sessions are marked in bold: 10 11 13 15 16 17 18. The difficulty is now 2.

In Case #2: Tambourine can add up to six sessions. The added sessions are marked in bold: 9 10 12 14 16 18 20 23 26 29 30. The difficulty is now 3.

In Case #3: Tambourine can add up to three sessions. The added sessions are marked in bold: 1 2 3 4 5 6 7 8 9 10. The difficulty is now 1. Note that Tambourine only added two sessions.

 

  • Note #1: Only Sample #1 is a valid input for Test set 1. Consequently, Sample #1 will be used as a sample test set for your submissions.
  • Note #2: Unlike previous editions, in Kick Start 2020, all test sets are visible verdict test sets, meaning you receive instant feedback upon submission.

题意:数组有N个递增的数字,希望加K个数字进去使得数字间的差值最大的最小。

解法:输入的时候遍历一遍数组,求出当前差值最大多少,然后二分这个差值,判断的时候就模拟一下需要插几个数字进去,数字够用肯定可以成功。

 1 #include<iostream>
 2 #include<cstdio>
 3 #include<cstring>
 4 #include<cmath>
 5 #include<vector>
 6 #include<algorithm>
 7 #include<map>
 8 #include<stack>
 9 #include<queue>
10 using namespace std;
11 #define PI 3.14159
12 #define mm(a,b) memset(a,b,sizeof(a))
13 const int maxn = 1e5 + 10;
14 const int inf = 0x3f3f3f3f;
15 int gcd(int a,int b) {
16     return b>0 ? gcd(b,a%b):a;
17 }
18 int arr[maxn];
19 int n,k;
20 bool check(int d)
21 {
22     int valid=k;
23     for(int i=1;i<n;i++)
24     {
25         if(arr[i]-arr[i-1]>d)
26         {
27             if((arr[i]-arr[i-1])%d==0)
28             {
29                 valid=valid-(arr[i]-arr[i-1])/d+1;
30             }
31             else valid=valid-(arr[i]-arr[i-1])/d;
32             
33             if(valid<0)
34             {
35                 return false;
36             }
37         }
38     }
39     if(valid>=0) return true;
40     return false;
41 }
42 int Solve(int l,int r)
43 {
44     int ans=-1;
45     while(l<=r)
46     {
47         int mid=(l+r)/2;
48         if(check(mid))
49         {
50             ans=mid;
51             r=mid-1;
52         }
53         else
54         {
55             l=mid+1;
56         }
57     }
58     return ans;
59 }
60 
61 int main()
62 {
63     int T;
64     scanf("%d",&T);
65     int ccase=1;
66     while(T--)
67     {
68         scanf("%d %d",&n,&k);
69         int diff=0;
70         scanf("%d",&arr[0]);
71         for(int i=1;i<n;i++)
72         {
73             scanf("%d",&arr[i]);
74             diff=max(diff,arr[i]-arr[i-1]);
75         }
76         int ans=Solve(1,diff);
77         printf("Case #%d: %d\n",ccase,ans);
78         ccase++;
79     }
80     return 0;
81 }

 

基于机器学习进行贷款中风险预测的Python代码及详细文档和PPT(高分项目),个人经导师指导并认可通过的高分设计项目,评审分98分,项目中的源码都是经过本地编译过可运行的,都经过严格调试,确保可以运行!主要针对计算机相关专业的正在做大作业、毕业设计的学生和需要项目实战练习的学习者,资源项目的难度比较适中,内容都是经过助教老师审定过的能够满足学习、使用需求,如果有需要的话可以放心下载使用。 基于机器学习进行贷款中风险预测的Python代码及详细文档和PPT(高分项目)基于机器学习进行贷款中风险预测的Python代码及详细文档和PPT(高分项目)基于机器学习进行贷款中风险预测的Python代码及详细文档和PPT(高分项目)基于机器学习进行贷款中风险预测的Python代码及详细文档和PPT(高分项目)基于机器学习进行贷款中风险预测的Python代码及详细文档和PPT(高分项目)基于机器学习进行贷款中风险预测的Python代码及详细文档和PPT(高分项目)基于机器学习进行贷款中风险预测的Python代码及详细文档和PPT(高分项目)基于机器学习进行贷款中风险预测的Python代码及详细文档和PPT(高分项目)基于机器学习进行贷款中风险预测的Python代码及详细文档和PPT(高分项目)基于机器学习进行贷款中风险预测的Python代码及详细文档和PPT(高分项目)基于机器学习进行贷款中风险预测的Python代码及详细文档和PPT(高分项目)基于机器学习进行贷款中风险预测的Python代码及详细文档和PPT(高分项目)基于机器学习进行贷款中风险预测的Python代码及详细文档和PPT(高分项目)基于机器学习进行贷款中风险预测的Python代码及详细文档和PPT(高分项目)基于机器学习进行贷款中风险预测的Python代码及详细文档和PPT(高分项目)基于机器学习进行贷款中风险预测的P
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值