Codeforces Round #424 (Div. 2, rated, based on VK Cup Finals) Problem F (Codeforces 831F) - 数论 - 暴力

Vladimir wants to modernize partitions in his office. To make the office more comfortable he decided to remove a partition and plant several bamboos in a row. He thinks it would be nice if there are n bamboos in a row, and the i-th from the left is ai meters high.

Vladimir has just planted n bamboos in a row, each of which has height 0 meters right now, but they grow 1 meter each day. In order to make the partition nice Vladimir can cut each bamboo once at any height (no greater that the height of the bamboo), and then the bamboo will stop growing.

Vladimir wants to check the bamboos each d days (i.e. d days after he planted, then after 2d days and so on), and cut the bamboos that reached the required height. Vladimir wants the total length of bamboo parts he will cut off to be no greater than k meters.

What is the maximum value d he can choose so that he can achieve what he wants without cutting off more than k meters of bamboo?

Input

The first line contains two integers n and k (1 ≤ n ≤ 100, 1 ≤ k ≤ 1011) — the number of bamboos and the maximum total length of cut parts, in meters.

The second line contains n integers a1, a2, ..., an (1 ≤ ai ≤ 109) — the required heights of bamboos, in meters.

Output

Print a single integer — the maximum value of d such that Vladimir can reach his goal.

Examples

input

3 41 3 5

output

3

input

3 4010 30 50

output

32

Note

In the first example Vladimir can check bamboos each 3 days. Then he will cut the first and the second bamboos after 3 days, and the third bamboo after 6 days. The total length of cut parts is 2 + 0 + 1 = 3 meters.



  题目大意 求这样一个最大的d使得

  整理一下可以得到条件是

  有注意到的取值个数为

  还是说明一下,设

  1)当时,显然至多个取值。

  2)当时,显然有,这个的取值个数也是的。

  因此可以发现当d等于一个值的时候可能和另一个d值的时候是等价的。

  所以我们把所有的取值当成一个点,安插在数轴上,然后一段一段地进行枚举。因为每一段内的d都是等价的,所以只需要用每一段的左端点计算和,然后判断是否在区间内,如果是就用它去更新答案。

Code

  1 /**
  2  * Codeforces
  3  * Problem#831F
  4  * Accepted
  5  * Time:997ms
  6  * Memory:100400k
  7  */
  8 #include <iostream>
  9 #include <cstdio>
 10 #include <ctime>
 11 #include <cmath>
 12 #include <cctype>
 13 #include <cstring>
 14 #include <cstdlib>
 15 #include <fstream>
 16 #include <sstream>
 17 #include <algorithm>
 18 #include <map>
 19 #include <set>
 20 #include <stack>
 21 #include <queue>
 22 #include <vector>
 23 #include <stack>
 24 #ifndef WIN32
 25 #define Auto "%lld"
 26 #else
 27 #define Auto "%I64d"
 28 #endif
 29 using namespace std;
 30 typedef bool boolean;
 31 const signed int inf = (signed)((1u << 31) - 1);
 32 const signed long long llf = (signed long long)((1ull << 63) - 1);
 33 const double eps = 1e-6;
 34 const int binary_limit = 128;
 35 #define smin(a, b) a = min(a, b)
 36 #define smax(a, b) a = max(a, b)
 37 #define max3(a, b, c) max(a, max(b, c))
 38 #define min3(a, b, c) min(a, min(b, c))
 39 template<typename T>
 40 inline boolean readInteger(T& u){
 41     char x;
 42     int aFlag = 1;
 43     while(!isdigit((x = getchar())) && x != ‘-‘ && x != -1);
 44     if(x == -1) {
 45         ungetc(x, stdin);
 46         return false;
 47     }
 48     if(x == ‘-‘){
 49         x = getchar();
 50         aFlag = -1;
 51     }
 52     for(u = x - ‘0‘; isdigit((x = getchar())); u = (u << 1) + (u << 3) + x - ‘0‘);
 53     ungetc(x, stdin);
 54     u *= aFlag;
 55     return true;
 56 }
 57
 58 #define LL long long
 59
 60 int n;
 61 LL C;
 62 int* a;
 63 vector<LL> seg;
 64
 65 template<typename T>
 66 T ceil(T a, T b) {
 67     return (a + b - 1) / b;
 68 }
 69
 70 inline void init() {
 71     readInteger(n);
 72     readInteger(C);
 73     seg.push_back(1);
 74     a = new int[(n + 1)];
 75     for(int i = 1, x; i <= n; i++) {
 76         readInteger(a[i]);
 77         for(int j = 1; j * j <= a[i]; j++)
 78             seg.push_back(j), seg.push_back(ceil(a[i], j));
 79         C += a[i];
 80     }
 81     seg.push_back(llf);
 82 }
 83
 84 LL res = 1;
 85 inline void solve() {
 86     sort(seg.begin(), seg.end());
 87     int m = unique(seg.begin(), seg.end()) - seg.begin() - 1;
 88     for(int i = 0; i < m; i++) {
 89         LL l = seg[i], r = seg[i + 1], temp = 0;
 90         for(int i = 1; i <= n; i++)
 91             temp += ceil((LL)a[i], l);
 92         LL d = C / temp;
 93         if(d >= l && d < r && d > res)
 94             res = d;
 95     }
 96     printf(Auto"\n", res);
 97 }
 98
 99 int main() {
100     init();
101     solve();
102     return 0;
103 }
时间: 2024-10-23 21:19:38

Codeforces Round #424 (Div. 2, rated, based on VK Cup Finals) Problem F (Codeforces 831F) - 数论 - 暴力的相关文章

Codeforces Round #424 (Div. 2, rated, based on VK Cup Finals) Problem D (Codeforces 831D) - 贪心 - 二分答案

There are n people and k keys on a straight line. Every person wants to get to the office which is located on the line as well. To do that, he needs to reach some point with a key, take the key and then go to the office. Once a key is taken by somebo

Codeforces Round #424 (Div. 2, rated, based on VK Cup Finals)

D题fst了,生无可恋.第二场rated的CF,打得精神恍惚 A. Unimodal Array 题意:判断数列是否是单峰的. 像题意那样分为三个阶段随便判一判就好了 #include<iostream> #include<cstdio> #include<cstring> #include<cstdlib> using namespace std; int n,x[105],part=1; bool f=1; int main() { scanf(&quo

Codeforces Round #424 (Div. 2, rated, based on VK Cup Finals)E. Cards Sorting

题意:有n个数字,我遍历过去,如果他是当前最小值,就删除,否则放到最后面去,问得遍历多少个数字,(直到所有数字消失 思路:我们保存每个数字的位置,这个数字是否能删除,如果他在上一个数字的最后一个位置后面就可以删除了,那么标记下+树状数组(我这里的y表示的就是上一个数删除的最后一个位置) 1 #include<bits/stdc++.h> 2 using namespace std; 3 typedef long long ll; 4 const int N=1e5+10; 5 6 int a[

Codeforces Round #424 (Div. 2, rated, based on VK Cup Finals) Cards Sorting(树状数组)

Cards Sorting time limit per test 1 second memory limit per test 256 megabytes input standard input output standard output Vasily has a deck of cards consisting of n cards. There is an integer on each of the cards, this integer is between 1 and 100?0

【Splay】Codeforces Round #424 (Div. 1, rated, based on VK Cup Finals) B. Cards Sorting

Splay要支持找最左侧的最小值所在的位置.类似线段树一样处理一下,如果左子树最小值等于全局最小值,就查左子树:否则如果当前节点等于全局最小值,就查当前节点:否则查右子树. 为了统计答案,当然还得维护子树大小的函数. 找到位置以后,直接将左右子树交换即可.不需要打标记. 删除节点时,直接将其前驱(是指序列下标的前驱,就是将待删除节点Splay到根后,左子树的最右节点)Splay到根,将其后继(类似)Splay到根的儿子. 然后将后继的左儿子删除即可. 别忘了及时Maintain(); 这份代码的

【推导】Codeforces Round #424 (Div. 1, rated, based on VK Cup Finals) A. Office Keys

选择的钥匙一定是连续的,人和钥匙一定从左到右连续对应. 就枚举钥匙区间即可. #include<cstdio> #include<algorithm> using namespace std; int Abs(int x){ return x<0 ? (-x) : x; } int n,K,p,a[1010],ans=2147483647,b[2010]; int main(){ scanf("%d%d%d",&n,&K,&p);

A. Office Keys (from Codeforces Round #424 (Div. 1, rated, based on VK Cup Finals) )

1 #include <iostream> 2 #include <stdio.h> 3 #include <string.h> 4 #include <algorithm> 5 using namespace std; 6 7 int a[150000]; 8 int b[150000]; 9 int dp[1005][1005]; 10 //dp[i][j] 前i个人从前j个药匙中到达终点的最小时间 11 12 int main() 13 { 14 in

Codeforces Round #423 (Div. 2, rated, based on VK Cup Finals) Problem A - B

Pronlem A In a small restaurant there are a tables for one person and b tables for two persons. It it known that n groups of people come today, each consisting of one or two people. If a group consist of one person, it is seated at a vacant one-seate

Codeforces Round #423 (Div. 2, rated, based on VK Cup Finals)D. High Load

题意:出n个点,其中k个叶子节点,问构造出的树最远的两个点最近是多少 思路:以一个点为中心,然后m个伸出,一层层扩散,(n-1)%m==k,如果k==0,即可以平分,长度就是2*(n-1)/m,如果取模为k==1,说明多出一个,+1,其他的话,就是最后一层补k个,但是最长的还是+2 1 #include<bits/stdc++.h> 2 using namespace std; 3 4 int main(){ 5 int n,m; 6 cin>>n>>m; 7 int