Search is not available for this dataset
name
stringlengths 2
112
| description
stringlengths 29
13k
| source
int64 1
7
| difficulty
int64 0
25
| solution
stringlengths 7
983k
| language
stringclasses 4
values |
---|---|---|---|---|---|
p00227 Thanksgiving | As bad weather continues and vegetable prices soar, Seven-Eleven is offering customers bulk purchase sales of vegetables. The store is very busy, as you can get vegetables that are hard to find in stores at reasonable prices.
One day, a group of three good friends living in the Matsunaga housing complex bloomed with an advertisement for Seven-Eleven. Since this sale was called "Customer Thanksgiving Day", the highlight is that the cheapest vegetables in the bag are free. When I read the advertisement, it looks like the following sale.
* Up to m vegetables can be packed in one bag.
* For bags packed with m vegetables, the cheapest vegetables are free.
* Bags with less than m vegetables are not eligible for the discount.
The three went shopping at Seven Mart immediately.
When the three people who met outside the store after shopping were satisfied with the fact that they were able to buy a lot at a low price, they apparently found that they were all buying the same vegetables. One person said, "It's really cheap, isn't it? This is XXX yen!", And the other was surprised, "What? I was ** yen higher than that! Why?", And the rest One of them saw the receipt and noticed that he bought the cheapest one.
Now, how can you pack the bag at the lowest purchase price? Enter the number of vegetables to purchase, the number of vegetables in the bag, and the price of each vegetable, and create a program that outputs the minimum purchase price.
Input
A sequence of multiple datasets is given as input. The end of the input is indicated by two lines of zeros. Each dataset is given in the following format:
n m
p1 p2 ... pn
The first line gives the number of vegetables to buy n (1 ≤ n ≤ 1000) and the number of vegetables to put in the bag m (1 ≤ m ≤ 1000). The second line gives the price pi (10 ≤ pi ≤ 10000) for each vegetable.
The number of datasets does not exceed 100.
Output
Prints the minimum purchase price on one line for each input dataset.
Example
Input
4 2
50 40 100 80
7 3
400 300 100 700 200 600 500
0 0
Output
150
2100 | 7 | 0 | #include<iostream>
#include<algorithm>
using namespace std;
int main(){
int n,m;
while(cin>>n>>m,n){
int veg[n];
for(int i=0;i<n;i++)cin>>veg[i];
sort(veg,veg+n,greater<int>());
int res=0;
for(int i=0;i<n;i++){
if((i+1)%m==0)continue;
res+=veg[i];
}
cout << res << endl;
}
return 0;
} | CPP |
p00227 Thanksgiving | As bad weather continues and vegetable prices soar, Seven-Eleven is offering customers bulk purchase sales of vegetables. The store is very busy, as you can get vegetables that are hard to find in stores at reasonable prices.
One day, a group of three good friends living in the Matsunaga housing complex bloomed with an advertisement for Seven-Eleven. Since this sale was called "Customer Thanksgiving Day", the highlight is that the cheapest vegetables in the bag are free. When I read the advertisement, it looks like the following sale.
* Up to m vegetables can be packed in one bag.
* For bags packed with m vegetables, the cheapest vegetables are free.
* Bags with less than m vegetables are not eligible for the discount.
The three went shopping at Seven Mart immediately.
When the three people who met outside the store after shopping were satisfied with the fact that they were able to buy a lot at a low price, they apparently found that they were all buying the same vegetables. One person said, "It's really cheap, isn't it? This is XXX yen!", And the other was surprised, "What? I was ** yen higher than that! Why?", And the rest One of them saw the receipt and noticed that he bought the cheapest one.
Now, how can you pack the bag at the lowest purchase price? Enter the number of vegetables to purchase, the number of vegetables in the bag, and the price of each vegetable, and create a program that outputs the minimum purchase price.
Input
A sequence of multiple datasets is given as input. The end of the input is indicated by two lines of zeros. Each dataset is given in the following format:
n m
p1 p2 ... pn
The first line gives the number of vegetables to buy n (1 ≤ n ≤ 1000) and the number of vegetables to put in the bag m (1 ≤ m ≤ 1000). The second line gives the price pi (10 ≤ pi ≤ 10000) for each vegetable.
The number of datasets does not exceed 100.
Output
Prints the minimum purchase price on one line for each input dataset.
Example
Input
4 2
50 40 100 80
7 3
400 300 100 700 200 600 500
0 0
Output
150
2100 | 7 | 0 | #include<iostream>
#include<algorithm>
using namespace std;
int n, m, x[1000000];
long long sum1, sum2;
int main() {
while (true) {
sum1 = 0; sum2 = 0;
cin >> n >> m;
if (n == 0 && m == 0) { break; }
for (int i = 0; i < n; i++) {
cin >> x[i];
sum1 += x[i];
}
sort(x, x + n);
for (int i = n - m; i >= 0; i -= m) {
sum2 += x[i];
}
cout << sum1 - sum2 << endl;
}
return 0;
} | CPP |
p00227 Thanksgiving | As bad weather continues and vegetable prices soar, Seven-Eleven is offering customers bulk purchase sales of vegetables. The store is very busy, as you can get vegetables that are hard to find in stores at reasonable prices.
One day, a group of three good friends living in the Matsunaga housing complex bloomed with an advertisement for Seven-Eleven. Since this sale was called "Customer Thanksgiving Day", the highlight is that the cheapest vegetables in the bag are free. When I read the advertisement, it looks like the following sale.
* Up to m vegetables can be packed in one bag.
* For bags packed with m vegetables, the cheapest vegetables are free.
* Bags with less than m vegetables are not eligible for the discount.
The three went shopping at Seven Mart immediately.
When the three people who met outside the store after shopping were satisfied with the fact that they were able to buy a lot at a low price, they apparently found that they were all buying the same vegetables. One person said, "It's really cheap, isn't it? This is XXX yen!", And the other was surprised, "What? I was ** yen higher than that! Why?", And the rest One of them saw the receipt and noticed that he bought the cheapest one.
Now, how can you pack the bag at the lowest purchase price? Enter the number of vegetables to purchase, the number of vegetables in the bag, and the price of each vegetable, and create a program that outputs the minimum purchase price.
Input
A sequence of multiple datasets is given as input. The end of the input is indicated by two lines of zeros. Each dataset is given in the following format:
n m
p1 p2 ... pn
The first line gives the number of vegetables to buy n (1 ≤ n ≤ 1000) and the number of vegetables to put in the bag m (1 ≤ m ≤ 1000). The second line gives the price pi (10 ≤ pi ≤ 10000) for each vegetable.
The number of datasets does not exceed 100.
Output
Prints the minimum purchase price on one line for each input dataset.
Example
Input
4 2
50 40 100 80
7 3
400 300 100 700 200 600 500
0 0
Output
150
2100 | 7 | 0 | #include<iostream>
#include<algorithm>
#include<functional>
using namespace std;
int main(){
int n, m;
while(cin >> n >> m, n || m){
int price[10010];
int ans = 0;
for(int i=1; i <= n; i++)
cin >> price[i];
sort(price+1, price+n+1, greater<int>());
for(int i=1; i <= n; i++){
if(i % m == 0) continue;
ans += price[i];
}
cout << ans << endl;
}
} | CPP |
p00227 Thanksgiving | As bad weather continues and vegetable prices soar, Seven-Eleven is offering customers bulk purchase sales of vegetables. The store is very busy, as you can get vegetables that are hard to find in stores at reasonable prices.
One day, a group of three good friends living in the Matsunaga housing complex bloomed with an advertisement for Seven-Eleven. Since this sale was called "Customer Thanksgiving Day", the highlight is that the cheapest vegetables in the bag are free. When I read the advertisement, it looks like the following sale.
* Up to m vegetables can be packed in one bag.
* For bags packed with m vegetables, the cheapest vegetables are free.
* Bags with less than m vegetables are not eligible for the discount.
The three went shopping at Seven Mart immediately.
When the three people who met outside the store after shopping were satisfied with the fact that they were able to buy a lot at a low price, they apparently found that they were all buying the same vegetables. One person said, "It's really cheap, isn't it? This is XXX yen!", And the other was surprised, "What? I was ** yen higher than that! Why?", And the rest One of them saw the receipt and noticed that he bought the cheapest one.
Now, how can you pack the bag at the lowest purchase price? Enter the number of vegetables to purchase, the number of vegetables in the bag, and the price of each vegetable, and create a program that outputs the minimum purchase price.
Input
A sequence of multiple datasets is given as input. The end of the input is indicated by two lines of zeros. Each dataset is given in the following format:
n m
p1 p2 ... pn
The first line gives the number of vegetables to buy n (1 ≤ n ≤ 1000) and the number of vegetables to put in the bag m (1 ≤ m ≤ 1000). The second line gives the price pi (10 ≤ pi ≤ 10000) for each vegetable.
The number of datasets does not exceed 100.
Output
Prints the minimum purchase price on one line for each input dataset.
Example
Input
4 2
50 40 100 80
7 3
400 300 100 700 200 600 500
0 0
Output
150
2100 | 7 | 0 | #include <iostream>
#include <algorithm>
using namespace std;
int main(){
int n,m;
while(cin >> n >> m , n + m){
int yasai[1000] = {0};
for(int i = 1 ; i <= n ; i++){
cin >> yasai[i];
}
sort(yasai,yasai+(n+1),greater<int>());
for(int i = n ; i >0 ; i--){
yasai[i] = yasai[i-1];
}
int sum = 0;
for(int i = 1 ; i <= n ; i++){
if(i%m != 0)sum+=yasai[i];
}
cout << sum << endl;
}
} | CPP |
p00227 Thanksgiving | As bad weather continues and vegetable prices soar, Seven-Eleven is offering customers bulk purchase sales of vegetables. The store is very busy, as you can get vegetables that are hard to find in stores at reasonable prices.
One day, a group of three good friends living in the Matsunaga housing complex bloomed with an advertisement for Seven-Eleven. Since this sale was called "Customer Thanksgiving Day", the highlight is that the cheapest vegetables in the bag are free. When I read the advertisement, it looks like the following sale.
* Up to m vegetables can be packed in one bag.
* For bags packed with m vegetables, the cheapest vegetables are free.
* Bags with less than m vegetables are not eligible for the discount.
The three went shopping at Seven Mart immediately.
When the three people who met outside the store after shopping were satisfied with the fact that they were able to buy a lot at a low price, they apparently found that they were all buying the same vegetables. One person said, "It's really cheap, isn't it? This is XXX yen!", And the other was surprised, "What? I was ** yen higher than that! Why?", And the rest One of them saw the receipt and noticed that he bought the cheapest one.
Now, how can you pack the bag at the lowest purchase price? Enter the number of vegetables to purchase, the number of vegetables in the bag, and the price of each vegetable, and create a program that outputs the minimum purchase price.
Input
A sequence of multiple datasets is given as input. The end of the input is indicated by two lines of zeros. Each dataset is given in the following format:
n m
p1 p2 ... pn
The first line gives the number of vegetables to buy n (1 ≤ n ≤ 1000) and the number of vegetables to put in the bag m (1 ≤ m ≤ 1000). The second line gives the price pi (10 ≤ pi ≤ 10000) for each vegetable.
The number of datasets does not exceed 100.
Output
Prints the minimum purchase price on one line for each input dataset.
Example
Input
4 2
50 40 100 80
7 3
400 300 100 700 200 600 500
0 0
Output
150
2100 | 7 | 0 | #include<iostream>
#include<queue>
#define loop(i,a,b) for(int i=a;i<b;i++)
#define rep(i,a) loop(i,0,a)
using namespace std;
int main(){
int n,m,dt;
while(1){
cin>>n>>m;
if(!(n&&m))break;
priority_queue<int> que;
rep(i,n){cin>>dt;que.push(dt);}
int cnt=0,sum=0;
while(!que.empty()){
cnt++;
if(cnt!=m)sum+=que.top();
else cnt=0;
que.pop();
}
cout<<sum<<endl;
}
return 0;
} | CPP |
p00227 Thanksgiving | As bad weather continues and vegetable prices soar, Seven-Eleven is offering customers bulk purchase sales of vegetables. The store is very busy, as you can get vegetables that are hard to find in stores at reasonable prices.
One day, a group of three good friends living in the Matsunaga housing complex bloomed with an advertisement for Seven-Eleven. Since this sale was called "Customer Thanksgiving Day", the highlight is that the cheapest vegetables in the bag are free. When I read the advertisement, it looks like the following sale.
* Up to m vegetables can be packed in one bag.
* For bags packed with m vegetables, the cheapest vegetables are free.
* Bags with less than m vegetables are not eligible for the discount.
The three went shopping at Seven Mart immediately.
When the three people who met outside the store after shopping were satisfied with the fact that they were able to buy a lot at a low price, they apparently found that they were all buying the same vegetables. One person said, "It's really cheap, isn't it? This is XXX yen!", And the other was surprised, "What? I was ** yen higher than that! Why?", And the rest One of them saw the receipt and noticed that he bought the cheapest one.
Now, how can you pack the bag at the lowest purchase price? Enter the number of vegetables to purchase, the number of vegetables in the bag, and the price of each vegetable, and create a program that outputs the minimum purchase price.
Input
A sequence of multiple datasets is given as input. The end of the input is indicated by two lines of zeros. Each dataset is given in the following format:
n m
p1 p2 ... pn
The first line gives the number of vegetables to buy n (1 ≤ n ≤ 1000) and the number of vegetables to put in the bag m (1 ≤ m ≤ 1000). The second line gives the price pi (10 ≤ pi ≤ 10000) for each vegetable.
The number of datasets does not exceed 100.
Output
Prints the minimum purchase price on one line for each input dataset.
Example
Input
4 2
50 40 100 80
7 3
400 300 100 700 200 600 500
0 0
Output
150
2100 | 7 | 0 | import java.util.Arrays;
import java.util.Scanner;
public class Main {
public static void main(String[] args) {
try (Scanner in = new Scanner(System.in)) {
solve(in);
}
}
private static void solve(Scanner in) {
// n m
// p1 p2 ... pn
while (true) {
int n = in.nextInt(), m = in.nextInt();
if (n == 0 && m == 0) {
break;
}
int[] p = new int[n];
for (int i = 0; i < n; i++) {
p[i] = in.nextInt();
}
Arrays.sort(p);
for (int i = 0; i < p.length / 2; i++) {
int tmp = p[i];
p[i] = p[p.length - 1 - i];
p[p.length - 1 - i] = tmp;
}
int sum = 0;
int i = 0;
int j = 0;
while (j < n) {
if (i == m - 1) {
i = 0;
} else {
i++;
sum += p[j];
}
j++;
}
System.out.println(sum);
}
}
} | JAVA |
p00227 Thanksgiving | As bad weather continues and vegetable prices soar, Seven-Eleven is offering customers bulk purchase sales of vegetables. The store is very busy, as you can get vegetables that are hard to find in stores at reasonable prices.
One day, a group of three good friends living in the Matsunaga housing complex bloomed with an advertisement for Seven-Eleven. Since this sale was called "Customer Thanksgiving Day", the highlight is that the cheapest vegetables in the bag are free. When I read the advertisement, it looks like the following sale.
* Up to m vegetables can be packed in one bag.
* For bags packed with m vegetables, the cheapest vegetables are free.
* Bags with less than m vegetables are not eligible for the discount.
The three went shopping at Seven Mart immediately.
When the three people who met outside the store after shopping were satisfied with the fact that they were able to buy a lot at a low price, they apparently found that they were all buying the same vegetables. One person said, "It's really cheap, isn't it? This is XXX yen!", And the other was surprised, "What? I was ** yen higher than that! Why?", And the rest One of them saw the receipt and noticed that he bought the cheapest one.
Now, how can you pack the bag at the lowest purchase price? Enter the number of vegetables to purchase, the number of vegetables in the bag, and the price of each vegetable, and create a program that outputs the minimum purchase price.
Input
A sequence of multiple datasets is given as input. The end of the input is indicated by two lines of zeros. Each dataset is given in the following format:
n m
p1 p2 ... pn
The first line gives the number of vegetables to buy n (1 ≤ n ≤ 1000) and the number of vegetables to put in the bag m (1 ≤ m ≤ 1000). The second line gives the price pi (10 ≤ pi ≤ 10000) for each vegetable.
The number of datasets does not exceed 100.
Output
Prints the minimum purchase price on one line for each input dataset.
Example
Input
4 2
50 40 100 80
7 3
400 300 100 700 200 600 500
0 0
Output
150
2100 | 7 | 0 | #include <cstdio>
#include <iostream>
#include <algorithm>
using namespace std;
int main()
{
int n, m;
int veg[1024];
int sum;
while (1){
sum = 0;
scanf("%d%d", &n, &m);
if (n == 0 && m == 0){
break;
}
for (int i = 0; i < n; i++){
scanf("%d", &veg[i]);
}
sort(veg, veg + n);
reverse(veg, veg + n);
for (int i = 0; i < n; i++){
if ((i + 1) % m != 0){
sum += veg[i];
}
}
cout << sum << endl;
}
return (0);
} | CPP |
p00227 Thanksgiving | As bad weather continues and vegetable prices soar, Seven-Eleven is offering customers bulk purchase sales of vegetables. The store is very busy, as you can get vegetables that are hard to find in stores at reasonable prices.
One day, a group of three good friends living in the Matsunaga housing complex bloomed with an advertisement for Seven-Eleven. Since this sale was called "Customer Thanksgiving Day", the highlight is that the cheapest vegetables in the bag are free. When I read the advertisement, it looks like the following sale.
* Up to m vegetables can be packed in one bag.
* For bags packed with m vegetables, the cheapest vegetables are free.
* Bags with less than m vegetables are not eligible for the discount.
The three went shopping at Seven Mart immediately.
When the three people who met outside the store after shopping were satisfied with the fact that they were able to buy a lot at a low price, they apparently found that they were all buying the same vegetables. One person said, "It's really cheap, isn't it? This is XXX yen!", And the other was surprised, "What? I was ** yen higher than that! Why?", And the rest One of them saw the receipt and noticed that he bought the cheapest one.
Now, how can you pack the bag at the lowest purchase price? Enter the number of vegetables to purchase, the number of vegetables in the bag, and the price of each vegetable, and create a program that outputs the minimum purchase price.
Input
A sequence of multiple datasets is given as input. The end of the input is indicated by two lines of zeros. Each dataset is given in the following format:
n m
p1 p2 ... pn
The first line gives the number of vegetables to buy n (1 ≤ n ≤ 1000) and the number of vegetables to put in the bag m (1 ≤ m ≤ 1000). The second line gives the price pi (10 ≤ pi ≤ 10000) for each vegetable.
The number of datasets does not exceed 100.
Output
Prints the minimum purchase price on one line for each input dataset.
Example
Input
4 2
50 40 100 80
7 3
400 300 100 700 200 600 500
0 0
Output
150
2100 | 7 | 0 | #include <iostream>
#include <algorithm>
using namespace std;
int main() {
int n, m;
int data[1000];
int sum;
while(1) {
cin >> n >> m;
if(n == 0 && m == 0) break;
for(int i = 0; i < n; i++) {
cin >> data[i];
}
sort(data, data+n);
sum = 0;
int i = n-1;
while(1) {
for(int j = 0; j < m; j++) {
if(i < 0) {
break;
}
if(j+1 == m) {
} else {
sum += data[i];
}
i--;
}
if(i < 0) break;
}
cout << sum << endl;
}
return 0;
} | CPP |
p00227 Thanksgiving | As bad weather continues and vegetable prices soar, Seven-Eleven is offering customers bulk purchase sales of vegetables. The store is very busy, as you can get vegetables that are hard to find in stores at reasonable prices.
One day, a group of three good friends living in the Matsunaga housing complex bloomed with an advertisement for Seven-Eleven. Since this sale was called "Customer Thanksgiving Day", the highlight is that the cheapest vegetables in the bag are free. When I read the advertisement, it looks like the following sale.
* Up to m vegetables can be packed in one bag.
* For bags packed with m vegetables, the cheapest vegetables are free.
* Bags with less than m vegetables are not eligible for the discount.
The three went shopping at Seven Mart immediately.
When the three people who met outside the store after shopping were satisfied with the fact that they were able to buy a lot at a low price, they apparently found that they were all buying the same vegetables. One person said, "It's really cheap, isn't it? This is XXX yen!", And the other was surprised, "What? I was ** yen higher than that! Why?", And the rest One of them saw the receipt and noticed that he bought the cheapest one.
Now, how can you pack the bag at the lowest purchase price? Enter the number of vegetables to purchase, the number of vegetables in the bag, and the price of each vegetable, and create a program that outputs the minimum purchase price.
Input
A sequence of multiple datasets is given as input. The end of the input is indicated by two lines of zeros. Each dataset is given in the following format:
n m
p1 p2 ... pn
The first line gives the number of vegetables to buy n (1 ≤ n ≤ 1000) and the number of vegetables to put in the bag m (1 ≤ m ≤ 1000). The second line gives the price pi (10 ≤ pi ≤ 10000) for each vegetable.
The number of datasets does not exceed 100.
Output
Prints the minimum purchase price on one line for each input dataset.
Example
Input
4 2
50 40 100 80
7 3
400 300 100 700 200 600 500
0 0
Output
150
2100 | 7 | 0 | #include <bits/stdc++.h>
using namespace std;
#define for_(i,a,b) for(int i=(a);i<(b);++i)
int n, m, p[1010];
int main() {
while (cin >> n >> m, n) {
for_(i,0,n) cin >> p[i];
sort(p, p + n, greater< int >());
int ans = 0, cnt = 1;
for_(i,0,n) {
if (cnt == m) {
cnt = 1;
} else {
++cnt;
ans += p[i];
}
}
cout << ans << endl;
}
} | CPP |
p00227 Thanksgiving | As bad weather continues and vegetable prices soar, Seven-Eleven is offering customers bulk purchase sales of vegetables. The store is very busy, as you can get vegetables that are hard to find in stores at reasonable prices.
One day, a group of three good friends living in the Matsunaga housing complex bloomed with an advertisement for Seven-Eleven. Since this sale was called "Customer Thanksgiving Day", the highlight is that the cheapest vegetables in the bag are free. When I read the advertisement, it looks like the following sale.
* Up to m vegetables can be packed in one bag.
* For bags packed with m vegetables, the cheapest vegetables are free.
* Bags with less than m vegetables are not eligible for the discount.
The three went shopping at Seven Mart immediately.
When the three people who met outside the store after shopping were satisfied with the fact that they were able to buy a lot at a low price, they apparently found that they were all buying the same vegetables. One person said, "It's really cheap, isn't it? This is XXX yen!", And the other was surprised, "What? I was ** yen higher than that! Why?", And the rest One of them saw the receipt and noticed that he bought the cheapest one.
Now, how can you pack the bag at the lowest purchase price? Enter the number of vegetables to purchase, the number of vegetables in the bag, and the price of each vegetable, and create a program that outputs the minimum purchase price.
Input
A sequence of multiple datasets is given as input. The end of the input is indicated by two lines of zeros. Each dataset is given in the following format:
n m
p1 p2 ... pn
The first line gives the number of vegetables to buy n (1 ≤ n ≤ 1000) and the number of vegetables to put in the bag m (1 ≤ m ≤ 1000). The second line gives the price pi (10 ≤ pi ≤ 10000) for each vegetable.
The number of datasets does not exceed 100.
Output
Prints the minimum purchase price on one line for each input dataset.
Example
Input
4 2
50 40 100 80
7 3
400 300 100 700 200 600 500
0 0
Output
150
2100 | 7 | 0 | #include<stdio.h>
int main(void)
{
int a,s,d[2000],f,g,h,i,j;
scanf("%d %d",&a,&s);
while(a!=0&&s!=0){
for(i=1;i<=a;i++){
scanf("%d",&d[i]);
}
for(i=1;i<=a;i++){
for(j=i;j<=a;j++){
if(d[i]<d[j]){
f=d[i];
d[i]=d[j];
d[j]=f;
}
}
}
g=0;
h=0;
for(i=1;i<=a;i++){
if(g==s-1){
g=0;
d[i]=0;
}
else if(g!=s-1){
g++;
h+=d[i];
}
//printf("%d %d\n",g,d[i]);
}
printf("%d\n",h);
scanf("%d %d",&a,&s);
}
return 0;
} | CPP |
p00227 Thanksgiving | As bad weather continues and vegetable prices soar, Seven-Eleven is offering customers bulk purchase sales of vegetables. The store is very busy, as you can get vegetables that are hard to find in stores at reasonable prices.
One day, a group of three good friends living in the Matsunaga housing complex bloomed with an advertisement for Seven-Eleven. Since this sale was called "Customer Thanksgiving Day", the highlight is that the cheapest vegetables in the bag are free. When I read the advertisement, it looks like the following sale.
* Up to m vegetables can be packed in one bag.
* For bags packed with m vegetables, the cheapest vegetables are free.
* Bags with less than m vegetables are not eligible for the discount.
The three went shopping at Seven Mart immediately.
When the three people who met outside the store after shopping were satisfied with the fact that they were able to buy a lot at a low price, they apparently found that they were all buying the same vegetables. One person said, "It's really cheap, isn't it? This is XXX yen!", And the other was surprised, "What? I was ** yen higher than that! Why?", And the rest One of them saw the receipt and noticed that he bought the cheapest one.
Now, how can you pack the bag at the lowest purchase price? Enter the number of vegetables to purchase, the number of vegetables in the bag, and the price of each vegetable, and create a program that outputs the minimum purchase price.
Input
A sequence of multiple datasets is given as input. The end of the input is indicated by two lines of zeros. Each dataset is given in the following format:
n m
p1 p2 ... pn
The first line gives the number of vegetables to buy n (1 ≤ n ≤ 1000) and the number of vegetables to put in the bag m (1 ≤ m ≤ 1000). The second line gives the price pi (10 ≤ pi ≤ 10000) for each vegetable.
The number of datasets does not exceed 100.
Output
Prints the minimum purchase price on one line for each input dataset.
Example
Input
4 2
50 40 100 80
7 3
400 300 100 700 200 600 500
0 0
Output
150
2100 | 7 | 0 | while True:
n, m = map(int, input().split())
if n == 0:
break
plst = sorted(list(map(int, input().split())), reverse=True)
s = sum(plst)
for i in range(m - 1, n, m):
s -= plst[i]
print(s)
| PYTHON3 |
p00227 Thanksgiving | As bad weather continues and vegetable prices soar, Seven-Eleven is offering customers bulk purchase sales of vegetables. The store is very busy, as you can get vegetables that are hard to find in stores at reasonable prices.
One day, a group of three good friends living in the Matsunaga housing complex bloomed with an advertisement for Seven-Eleven. Since this sale was called "Customer Thanksgiving Day", the highlight is that the cheapest vegetables in the bag are free. When I read the advertisement, it looks like the following sale.
* Up to m vegetables can be packed in one bag.
* For bags packed with m vegetables, the cheapest vegetables are free.
* Bags with less than m vegetables are not eligible for the discount.
The three went shopping at Seven Mart immediately.
When the three people who met outside the store after shopping were satisfied with the fact that they were able to buy a lot at a low price, they apparently found that they were all buying the same vegetables. One person said, "It's really cheap, isn't it? This is XXX yen!", And the other was surprised, "What? I was ** yen higher than that! Why?", And the rest One of them saw the receipt and noticed that he bought the cheapest one.
Now, how can you pack the bag at the lowest purchase price? Enter the number of vegetables to purchase, the number of vegetables in the bag, and the price of each vegetable, and create a program that outputs the minimum purchase price.
Input
A sequence of multiple datasets is given as input. The end of the input is indicated by two lines of zeros. Each dataset is given in the following format:
n m
p1 p2 ... pn
The first line gives the number of vegetables to buy n (1 ≤ n ≤ 1000) and the number of vegetables to put in the bag m (1 ≤ m ≤ 1000). The second line gives the price pi (10 ≤ pi ≤ 10000) for each vegetable.
The number of datasets does not exceed 100.
Output
Prints the minimum purchase price on one line for each input dataset.
Example
Input
4 2
50 40 100 80
7 3
400 300 100 700 200 600 500
0 0
Output
150
2100 | 7 | 0 | # AOJ 0227: Thanksgiving
# Python3 2018.6.24 bal4u
while 1:
n, m = map(int, input().split())
if n == 0: break
p = list(map(int, input().split()))
p.sort(reverse=True)
ans = 0
for i in range(1, n+1):
if i % m: ans += p[i-1]
print(ans)
| PYTHON3 |
p00227 Thanksgiving | As bad weather continues and vegetable prices soar, Seven-Eleven is offering customers bulk purchase sales of vegetables. The store is very busy, as you can get vegetables that are hard to find in stores at reasonable prices.
One day, a group of three good friends living in the Matsunaga housing complex bloomed with an advertisement for Seven-Eleven. Since this sale was called "Customer Thanksgiving Day", the highlight is that the cheapest vegetables in the bag are free. When I read the advertisement, it looks like the following sale.
* Up to m vegetables can be packed in one bag.
* For bags packed with m vegetables, the cheapest vegetables are free.
* Bags with less than m vegetables are not eligible for the discount.
The three went shopping at Seven Mart immediately.
When the three people who met outside the store after shopping were satisfied with the fact that they were able to buy a lot at a low price, they apparently found that they were all buying the same vegetables. One person said, "It's really cheap, isn't it? This is XXX yen!", And the other was surprised, "What? I was ** yen higher than that! Why?", And the rest One of them saw the receipt and noticed that he bought the cheapest one.
Now, how can you pack the bag at the lowest purchase price? Enter the number of vegetables to purchase, the number of vegetables in the bag, and the price of each vegetable, and create a program that outputs the minimum purchase price.
Input
A sequence of multiple datasets is given as input. The end of the input is indicated by two lines of zeros. Each dataset is given in the following format:
n m
p1 p2 ... pn
The first line gives the number of vegetables to buy n (1 ≤ n ≤ 1000) and the number of vegetables to put in the bag m (1 ≤ m ≤ 1000). The second line gives the price pi (10 ≤ pi ≤ 10000) for each vegetable.
The number of datasets does not exceed 100.
Output
Prints the minimum purchase price on one line for each input dataset.
Example
Input
4 2
50 40 100 80
7 3
400 300 100 700 200 600 500
0 0
Output
150
2100 | 7 | 0 | #include <iostream>
#include <vector>
#include <algorithm>
using namespace std;
int main(void){
int n,m;
while(cin>>n>>m, n||m){
vector<int> p(n);
for(int i=0;i<n;++i) cin>>p[i];
sort(p.begin(), p.end(), greater<int>());
int sum=0,tmp=0;
for(int i=0;i<n-(n%m);++i){
tmp+=p[i];
if(i%m==m-1){
sum+=tmp-p[i];
tmp=0;
}
}
for(int i=n-(n%m);i<n;++i)sum+=p[i];
cout<<sum<<endl;
}
} | CPP |
p00227 Thanksgiving | As bad weather continues and vegetable prices soar, Seven-Eleven is offering customers bulk purchase sales of vegetables. The store is very busy, as you can get vegetables that are hard to find in stores at reasonable prices.
One day, a group of three good friends living in the Matsunaga housing complex bloomed with an advertisement for Seven-Eleven. Since this sale was called "Customer Thanksgiving Day", the highlight is that the cheapest vegetables in the bag are free. When I read the advertisement, it looks like the following sale.
* Up to m vegetables can be packed in one bag.
* For bags packed with m vegetables, the cheapest vegetables are free.
* Bags with less than m vegetables are not eligible for the discount.
The three went shopping at Seven Mart immediately.
When the three people who met outside the store after shopping were satisfied with the fact that they were able to buy a lot at a low price, they apparently found that they were all buying the same vegetables. One person said, "It's really cheap, isn't it? This is XXX yen!", And the other was surprised, "What? I was ** yen higher than that! Why?", And the rest One of them saw the receipt and noticed that he bought the cheapest one.
Now, how can you pack the bag at the lowest purchase price? Enter the number of vegetables to purchase, the number of vegetables in the bag, and the price of each vegetable, and create a program that outputs the minimum purchase price.
Input
A sequence of multiple datasets is given as input. The end of the input is indicated by two lines of zeros. Each dataset is given in the following format:
n m
p1 p2 ... pn
The first line gives the number of vegetables to buy n (1 ≤ n ≤ 1000) and the number of vegetables to put in the bag m (1 ≤ m ≤ 1000). The second line gives the price pi (10 ≤ pi ≤ 10000) for each vegetable.
The number of datasets does not exceed 100.
Output
Prints the minimum purchase price on one line for each input dataset.
Example
Input
4 2
50 40 100 80
7 3
400 300 100 700 200 600 500
0 0
Output
150
2100 | 7 | 0 | #include<cstdio>
#include<iostream>
#include<algorithm>
using namespace std;
int main(void)
{
while (1)
{
int n, m, p[1000], sum = 0;
cin >> n >> m;
if (n == 0 && m == 0)break;
for (int i = 0; i < n; i++)
{
cin >> p[i];
sum += p[i];
}
sort(p, p + n);
for (int i = n - m; i >= 0; i -= m)
{
sum -= p[i];
}
cout << sum << endl;
}
} | CPP |
p00227 Thanksgiving | As bad weather continues and vegetable prices soar, Seven-Eleven is offering customers bulk purchase sales of vegetables. The store is very busy, as you can get vegetables that are hard to find in stores at reasonable prices.
One day, a group of three good friends living in the Matsunaga housing complex bloomed with an advertisement for Seven-Eleven. Since this sale was called "Customer Thanksgiving Day", the highlight is that the cheapest vegetables in the bag are free. When I read the advertisement, it looks like the following sale.
* Up to m vegetables can be packed in one bag.
* For bags packed with m vegetables, the cheapest vegetables are free.
* Bags with less than m vegetables are not eligible for the discount.
The three went shopping at Seven Mart immediately.
When the three people who met outside the store after shopping were satisfied with the fact that they were able to buy a lot at a low price, they apparently found that they were all buying the same vegetables. One person said, "It's really cheap, isn't it? This is XXX yen!", And the other was surprised, "What? I was ** yen higher than that! Why?", And the rest One of them saw the receipt and noticed that he bought the cheapest one.
Now, how can you pack the bag at the lowest purchase price? Enter the number of vegetables to purchase, the number of vegetables in the bag, and the price of each vegetable, and create a program that outputs the minimum purchase price.
Input
A sequence of multiple datasets is given as input. The end of the input is indicated by two lines of zeros. Each dataset is given in the following format:
n m
p1 p2 ... pn
The first line gives the number of vegetables to buy n (1 ≤ n ≤ 1000) and the number of vegetables to put in the bag m (1 ≤ m ≤ 1000). The second line gives the price pi (10 ≤ pi ≤ 10000) for each vegetable.
The number of datasets does not exceed 100.
Output
Prints the minimum purchase price on one line for each input dataset.
Example
Input
4 2
50 40 100 80
7 3
400 300 100 700 200 600 500
0 0
Output
150
2100 | 7 | 0 | #include <iostream>
#include <algorithm>
using namespace std;
int main()
{
int N,M;
while(cin >> N >> M,(N||M))
{
int a[1000],ans=0;
for(int i=0; i<N; i++)
{
cin >> a[i];
ans+=a[i];
}
sort(a,a+N);
reverse(a,a+N);
for(int i=M-1; i<N; i+=M)
ans-=a[i];
cout << ans << endl;
}
} | CPP |
p00227 Thanksgiving | As bad weather continues and vegetable prices soar, Seven-Eleven is offering customers bulk purchase sales of vegetables. The store is very busy, as you can get vegetables that are hard to find in stores at reasonable prices.
One day, a group of three good friends living in the Matsunaga housing complex bloomed with an advertisement for Seven-Eleven. Since this sale was called "Customer Thanksgiving Day", the highlight is that the cheapest vegetables in the bag are free. When I read the advertisement, it looks like the following sale.
* Up to m vegetables can be packed in one bag.
* For bags packed with m vegetables, the cheapest vegetables are free.
* Bags with less than m vegetables are not eligible for the discount.
The three went shopping at Seven Mart immediately.
When the three people who met outside the store after shopping were satisfied with the fact that they were able to buy a lot at a low price, they apparently found that they were all buying the same vegetables. One person said, "It's really cheap, isn't it? This is XXX yen!", And the other was surprised, "What? I was ** yen higher than that! Why?", And the rest One of them saw the receipt and noticed that he bought the cheapest one.
Now, how can you pack the bag at the lowest purchase price? Enter the number of vegetables to purchase, the number of vegetables in the bag, and the price of each vegetable, and create a program that outputs the minimum purchase price.
Input
A sequence of multiple datasets is given as input. The end of the input is indicated by two lines of zeros. Each dataset is given in the following format:
n m
p1 p2 ... pn
The first line gives the number of vegetables to buy n (1 ≤ n ≤ 1000) and the number of vegetables to put in the bag m (1 ≤ m ≤ 1000). The second line gives the price pi (10 ≤ pi ≤ 10000) for each vegetable.
The number of datasets does not exceed 100.
Output
Prints the minimum purchase price on one line for each input dataset.
Example
Input
4 2
50 40 100 80
7 3
400 300 100 700 200 600 500
0 0
Output
150
2100 | 7 | 0 | #include <iostream>
#include <queue>
#include <algorithm>
using namespace std;
int main(){
int m,n,a,b,sum, temp;
int ans;
priority_queue<int> que;
while(1) {
sum = 0;
cin>>n>>m;
if(n == 0 && m == 0){
break;
}
for(int i = 0; i<n; ++i){
cin>>a;
que.push(a);
}
for(int i = 1;i<=n;++i){
b = que.top();
que.pop();
if(i % m != 0){
sum += b;
}
}
cout << sum << endl;
}
return 0;
} | CPP |
p00227 Thanksgiving | As bad weather continues and vegetable prices soar, Seven-Eleven is offering customers bulk purchase sales of vegetables. The store is very busy, as you can get vegetables that are hard to find in stores at reasonable prices.
One day, a group of three good friends living in the Matsunaga housing complex bloomed with an advertisement for Seven-Eleven. Since this sale was called "Customer Thanksgiving Day", the highlight is that the cheapest vegetables in the bag are free. When I read the advertisement, it looks like the following sale.
* Up to m vegetables can be packed in one bag.
* For bags packed with m vegetables, the cheapest vegetables are free.
* Bags with less than m vegetables are not eligible for the discount.
The three went shopping at Seven Mart immediately.
When the three people who met outside the store after shopping were satisfied with the fact that they were able to buy a lot at a low price, they apparently found that they were all buying the same vegetables. One person said, "It's really cheap, isn't it? This is XXX yen!", And the other was surprised, "What? I was ** yen higher than that! Why?", And the rest One of them saw the receipt and noticed that he bought the cheapest one.
Now, how can you pack the bag at the lowest purchase price? Enter the number of vegetables to purchase, the number of vegetables in the bag, and the price of each vegetable, and create a program that outputs the minimum purchase price.
Input
A sequence of multiple datasets is given as input. The end of the input is indicated by two lines of zeros. Each dataset is given in the following format:
n m
p1 p2 ... pn
The first line gives the number of vegetables to buy n (1 ≤ n ≤ 1000) and the number of vegetables to put in the bag m (1 ≤ m ≤ 1000). The second line gives the price pi (10 ≤ pi ≤ 10000) for each vegetable.
The number of datasets does not exceed 100.
Output
Prints the minimum purchase price on one line for each input dataset.
Example
Input
4 2
50 40 100 80
7 3
400 300 100 700 200 600 500
0 0
Output
150
2100 | 7 | 0 | import java.util.Arrays;
import java.util.Scanner;
public class Main {
public static void main(String[] args) {
Scanner in = new Scanner(System.in);
int n, m;
while ((n = in.nextInt()) != 0 && (m = in.nextInt()) != 0) {
int[] yasai = new int[n];
for (int i = 0; i < n; i++) {
yasai[i] = in.nextInt();
}
Arrays.sort(yasai);
int price = 0;
for (int i = 1; i <= n; i++) {
if (i % m != 0) {
price += yasai[n - i];
}
}
System.out.println(price);
}
}
} | JAVA |
p00227 Thanksgiving | As bad weather continues and vegetable prices soar, Seven-Eleven is offering customers bulk purchase sales of vegetables. The store is very busy, as you can get vegetables that are hard to find in stores at reasonable prices.
One day, a group of three good friends living in the Matsunaga housing complex bloomed with an advertisement for Seven-Eleven. Since this sale was called "Customer Thanksgiving Day", the highlight is that the cheapest vegetables in the bag are free. When I read the advertisement, it looks like the following sale.
* Up to m vegetables can be packed in one bag.
* For bags packed with m vegetables, the cheapest vegetables are free.
* Bags with less than m vegetables are not eligible for the discount.
The three went shopping at Seven Mart immediately.
When the three people who met outside the store after shopping were satisfied with the fact that they were able to buy a lot at a low price, they apparently found that they were all buying the same vegetables. One person said, "It's really cheap, isn't it? This is XXX yen!", And the other was surprised, "What? I was ** yen higher than that! Why?", And the rest One of them saw the receipt and noticed that he bought the cheapest one.
Now, how can you pack the bag at the lowest purchase price? Enter the number of vegetables to purchase, the number of vegetables in the bag, and the price of each vegetable, and create a program that outputs the minimum purchase price.
Input
A sequence of multiple datasets is given as input. The end of the input is indicated by two lines of zeros. Each dataset is given in the following format:
n m
p1 p2 ... pn
The first line gives the number of vegetables to buy n (1 ≤ n ≤ 1000) and the number of vegetables to put in the bag m (1 ≤ m ≤ 1000). The second line gives the price pi (10 ≤ pi ≤ 10000) for each vegetable.
The number of datasets does not exceed 100.
Output
Prints the minimum purchase price on one line for each input dataset.
Example
Input
4 2
50 40 100 80
7 3
400 300 100 700 200 600 500
0 0
Output
150
2100 | 7 | 0 | #include<iostream>
#include<cmath>
#include<algorithm>
using namespace std;
int main(){
int m,n;
int b[1001];
while(cin >> n >> m,m || n){
int total=0;
int k=n/m;
for(int i=0;i<n;i++) cin >> b[i];
sort(b,b+n);
for(int i=1;i<=n;i++){
if(i%m) total+=b[n-i];
}
cout << total << endl;
}
} | CPP |
p00227 Thanksgiving | As bad weather continues and vegetable prices soar, Seven-Eleven is offering customers bulk purchase sales of vegetables. The store is very busy, as you can get vegetables that are hard to find in stores at reasonable prices.
One day, a group of three good friends living in the Matsunaga housing complex bloomed with an advertisement for Seven-Eleven. Since this sale was called "Customer Thanksgiving Day", the highlight is that the cheapest vegetables in the bag are free. When I read the advertisement, it looks like the following sale.
* Up to m vegetables can be packed in one bag.
* For bags packed with m vegetables, the cheapest vegetables are free.
* Bags with less than m vegetables are not eligible for the discount.
The three went shopping at Seven Mart immediately.
When the three people who met outside the store after shopping were satisfied with the fact that they were able to buy a lot at a low price, they apparently found that they were all buying the same vegetables. One person said, "It's really cheap, isn't it? This is XXX yen!", And the other was surprised, "What? I was ** yen higher than that! Why?", And the rest One of them saw the receipt and noticed that he bought the cheapest one.
Now, how can you pack the bag at the lowest purchase price? Enter the number of vegetables to purchase, the number of vegetables in the bag, and the price of each vegetable, and create a program that outputs the minimum purchase price.
Input
A sequence of multiple datasets is given as input. The end of the input is indicated by two lines of zeros. Each dataset is given in the following format:
n m
p1 p2 ... pn
The first line gives the number of vegetables to buy n (1 ≤ n ≤ 1000) and the number of vegetables to put in the bag m (1 ≤ m ≤ 1000). The second line gives the price pi (10 ≤ pi ≤ 10000) for each vegetable.
The number of datasets does not exceed 100.
Output
Prints the minimum purchase price on one line for each input dataset.
Example
Input
4 2
50 40 100 80
7 3
400 300 100 700 200 600 500
0 0
Output
150
2100 | 7 | 0 | #include <iostream>
#include <vector>
#include <algorithm>
int main(){
int n,m; //n:buy count m:pack count
while(std::cin >> n >> m){
if(n == 0 && m == 0)
break;
std::vector<int> price;
price.resize(n);
for(int i=0; i<n; ++i){
std::cin >> price[i];
}
std::sort(price.begin(), price.end(), std::greater<int>());
int sum=0;
for(int i=0; i<n; ++i){
if((i+1)%m != 0)
sum += price[i];
}
std::cout << sum << std::endl;
}
return 0;
} | CPP |
p00227 Thanksgiving | As bad weather continues and vegetable prices soar, Seven-Eleven is offering customers bulk purchase sales of vegetables. The store is very busy, as you can get vegetables that are hard to find in stores at reasonable prices.
One day, a group of three good friends living in the Matsunaga housing complex bloomed with an advertisement for Seven-Eleven. Since this sale was called "Customer Thanksgiving Day", the highlight is that the cheapest vegetables in the bag are free. When I read the advertisement, it looks like the following sale.
* Up to m vegetables can be packed in one bag.
* For bags packed with m vegetables, the cheapest vegetables are free.
* Bags with less than m vegetables are not eligible for the discount.
The three went shopping at Seven Mart immediately.
When the three people who met outside the store after shopping were satisfied with the fact that they were able to buy a lot at a low price, they apparently found that they were all buying the same vegetables. One person said, "It's really cheap, isn't it? This is XXX yen!", And the other was surprised, "What? I was ** yen higher than that! Why?", And the rest One of them saw the receipt and noticed that he bought the cheapest one.
Now, how can you pack the bag at the lowest purchase price? Enter the number of vegetables to purchase, the number of vegetables in the bag, and the price of each vegetable, and create a program that outputs the minimum purchase price.
Input
A sequence of multiple datasets is given as input. The end of the input is indicated by two lines of zeros. Each dataset is given in the following format:
n m
p1 p2 ... pn
The first line gives the number of vegetables to buy n (1 ≤ n ≤ 1000) and the number of vegetables to put in the bag m (1 ≤ m ≤ 1000). The second line gives the price pi (10 ≤ pi ≤ 10000) for each vegetable.
The number of datasets does not exceed 100.
Output
Prints the minimum purchase price on one line for each input dataset.
Example
Input
4 2
50 40 100 80
7 3
400 300 100 700 200 600 500
0 0
Output
150
2100 | 7 | 0 | while True:
try:
__, m = (lambda row: [int(row[i]) for i in range(len(row))])(input().split())
price = sorted(list(map(int, input().split())), reverse=True)
print(str(sum([price[i] for i in range(len(price)) if (i+1)%m != 0])))
except:
break
| PYTHON3 |
p00389 Pilling Blocks | We make a tower by stacking up blocks. The tower consists of several stages and each stage is constructed by connecting blocks horizontally. Each block is of the same weight and is tough enough to withstand the weight equivalent to up to $K$ blocks without crushing.
We have to build the tower abiding by the following conditions:
* Every stage of the tower has one or more blocks on it.
* Each block is loaded with weight that falls within the withstanding range of the block. The weight loaded on a block in a stage is evaluated by: total weight of all blocks above the stage divided by the number of blocks within the stage.
Given the number of blocks and the strength, make a program to evaluate the maximum height (i.e., stages) of the tower than can be constructed.
Input
The input is given in the following format.
$N$ $K$
The input line provides the number of blocks available $N$ ($1 \leq N \leq 10^5$) and the strength of the block $K$ ($1 \leq K \leq 10^5$).
Output
Output the maximum possible number of stages.
Examples
Input
4 2
Output
3
Input
5 2
Output
4 | 7 | 0 | #include <iostream>
#include<vector>
#include<algorithm>
#include<string>
#include<map>
#include<set>
#include<stack>
#include<queue>
#include<math.h>
using namespace std;
typedef long long ll;
#define int long long
typedef vector<int> VI;
typedef pair<int, int> pii;
#define fore(i,a) for(auto &i:a)
#define REP(i,n) for(int i=0;i<n;i++)
#define eREP(i,n) for(int i=0;i<=n;i++)
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define eFOR(i,a,b) for(int i=(a);i<=(b);++i)
#define SORT(c) sort((c).begin(),(c).end())
#define rSORT(c) sort((c).rbegin(),(c).rend())
#define LB(x,a) lower_bound((x).begin(),(x).end(),(a))
#define UB(x,a) upper_bound((x).begin(),(x).end(),(a))
#define INF 1000000000
#define LLINF 9223372036854775807
#define mod 1000000007
//vector<vector<int> > dp;
//vector<vector<vector<int> > > vvvi;
//dp=vector<vector<int> >(N, vector<int>(M,0));
//vector<pair<int,int> > v;
//v.push_back(make_pair(x,y));
//priority_queue<int,vector<int>, greater<int> > q2;
signed main(){
cin.tie(0);
ios::sync_with_stdio(false);
int N, K;
cin >> N >> K;
int ans = 0, cnt = 0;
while (N > 0) {
N--;
bool f = true;
int tmp = 1;
while (tmp*K < cnt) {
tmp++;
N--;
if (N < 0) {
f = false;
break;
}
}
cnt += tmp;
if(f)ans++;
//cout << tmp << endl;
}
cout << ans << endl;
return 0;
}
| CPP |
p00389 Pilling Blocks | We make a tower by stacking up blocks. The tower consists of several stages and each stage is constructed by connecting blocks horizontally. Each block is of the same weight and is tough enough to withstand the weight equivalent to up to $K$ blocks without crushing.
We have to build the tower abiding by the following conditions:
* Every stage of the tower has one or more blocks on it.
* Each block is loaded with weight that falls within the withstanding range of the block. The weight loaded on a block in a stage is evaluated by: total weight of all blocks above the stage divided by the number of blocks within the stage.
Given the number of blocks and the strength, make a program to evaluate the maximum height (i.e., stages) of the tower than can be constructed.
Input
The input is given in the following format.
$N$ $K$
The input line provides the number of blocks available $N$ ($1 \leq N \leq 10^5$) and the strength of the block $K$ ($1 \leq K \leq 10^5$).
Output
Output the maximum possible number of stages.
Examples
Input
4 2
Output
3
Input
5 2
Output
4 | 7 | 0 | #include <iostream>
using namespace std;
int main() {
int n, k;
cin >> n >> k;
int res = 0;
int row = 1;
int w = 0;
while ( n >= row ) {
// cout << w << " " << row << endl;
if ( row*k >= w ) {
++res;
w += row;
n -= row;
}
else if ( n >= row+1 ) ++row;
else break;
}
cout << res << endl;
return 0;
}
| CPP |
p00389 Pilling Blocks | We make a tower by stacking up blocks. The tower consists of several stages and each stage is constructed by connecting blocks horizontally. Each block is of the same weight and is tough enough to withstand the weight equivalent to up to $K$ blocks without crushing.
We have to build the tower abiding by the following conditions:
* Every stage of the tower has one or more blocks on it.
* Each block is loaded with weight that falls within the withstanding range of the block. The weight loaded on a block in a stage is evaluated by: total weight of all blocks above the stage divided by the number of blocks within the stage.
Given the number of blocks and the strength, make a program to evaluate the maximum height (i.e., stages) of the tower than can be constructed.
Input
The input is given in the following format.
$N$ $K$
The input line provides the number of blocks available $N$ ($1 \leq N \leq 10^5$) and the strength of the block $K$ ($1 \leq K \leq 10^5$).
Output
Output the maximum possible number of stages.
Examples
Input
4 2
Output
3
Input
5 2
Output
4 | 7 | 0 | n,k = map(int, input().split())
res = 0
row = 1
w = 0
while n >= row :
if row*k >= w :
res += 1
w += row
n -= row
elif n >= row+1 : row += 1
else : break
print(res)
| PYTHON3 |
p00389 Pilling Blocks | We make a tower by stacking up blocks. The tower consists of several stages and each stage is constructed by connecting blocks horizontally. Each block is of the same weight and is tough enough to withstand the weight equivalent to up to $K$ blocks without crushing.
We have to build the tower abiding by the following conditions:
* Every stage of the tower has one or more blocks on it.
* Each block is loaded with weight that falls within the withstanding range of the block. The weight loaded on a block in a stage is evaluated by: total weight of all blocks above the stage divided by the number of blocks within the stage.
Given the number of blocks and the strength, make a program to evaluate the maximum height (i.e., stages) of the tower than can be constructed.
Input
The input is given in the following format.
$N$ $K$
The input line provides the number of blocks available $N$ ($1 \leq N \leq 10^5$) and the strength of the block $K$ ($1 \leq K \leq 10^5$).
Output
Output the maximum possible number of stages.
Examples
Input
4 2
Output
3
Input
5 2
Output
4 | 7 | 0 | import java.io.*;
import java.util.*;
class Main {
void solve(){
Scanner sc = new Scanner(System.in);
int n = sc.nextInt(), k = sc.nextInt();
int res = 0;
int row = 1;
int w = 0;
while ( n >= row ) {
if ( row*k >= w ) {
++res;
w += row;
n -= row;
}
else if ( n >= row+1 ) ++row;
else break;
}
System.out.println( res );
}
public static void main(String[] a) { new Main().solve(); }
}
| JAVA |
p00389 Pilling Blocks | We make a tower by stacking up blocks. The tower consists of several stages and each stage is constructed by connecting blocks horizontally. Each block is of the same weight and is tough enough to withstand the weight equivalent to up to $K$ blocks without crushing.
We have to build the tower abiding by the following conditions:
* Every stage of the tower has one or more blocks on it.
* Each block is loaded with weight that falls within the withstanding range of the block. The weight loaded on a block in a stage is evaluated by: total weight of all blocks above the stage divided by the number of blocks within the stage.
Given the number of blocks and the strength, make a program to evaluate the maximum height (i.e., stages) of the tower than can be constructed.
Input
The input is given in the following format.
$N$ $K$
The input line provides the number of blocks available $N$ ($1 \leq N \leq 10^5$) and the strength of the block $K$ ($1 \leq K \leq 10^5$).
Output
Output the maximum possible number of stages.
Examples
Input
4 2
Output
3
Input
5 2
Output
4 | 7 | 0 | #include <bits/stdc++.h>
using namespace std;
int N, K;
int main() {
int h, m;
double rest;
h = 1;
cin >> N >> K;
rest = N;
while (true) {
m = rest / (K + 1) * K;
if (m == 0) {
break;
}
++h;
rest = m;
}
cout << h << endl;
return 0;
}
| CPP |
p00389 Pilling Blocks | We make a tower by stacking up blocks. The tower consists of several stages and each stage is constructed by connecting blocks horizontally. Each block is of the same weight and is tough enough to withstand the weight equivalent to up to $K$ blocks without crushing.
We have to build the tower abiding by the following conditions:
* Every stage of the tower has one or more blocks on it.
* Each block is loaded with weight that falls within the withstanding range of the block. The weight loaded on a block in a stage is evaluated by: total weight of all blocks above the stage divided by the number of blocks within the stage.
Given the number of blocks and the strength, make a program to evaluate the maximum height (i.e., stages) of the tower than can be constructed.
Input
The input is given in the following format.
$N$ $K$
The input line provides the number of blocks available $N$ ($1 \leq N \leq 10^5$) and the strength of the block $K$ ($1 \leq K \leq 10^5$).
Output
Output the maximum possible number of stages.
Examples
Input
4 2
Output
3
Input
5 2
Output
4 | 7 | 0 | #include "bits/stdc++.h"
#define rep(var,cnt) for(int (var)=0; (var)<(cnt); ++(var))
using namespace std;
using int64 = int64_t;
using pi=pair<int,int>;
template <int mod>
struct ModInt {
int x;
ModInt() : x(0) {}
ModInt(int64_t y) : x(y >= 0 ? y % mod : (mod - (-y) % mod) % mod) {}
ModInt &operator+=(const ModInt &p) {
if((x += p.x) >= mod) x -= mod;
return *this;
}
ModInt &operator-=(const ModInt &p) {
if((x += mod - p.x) >= mod) x -= mod;
return *this;
}
ModInt &operator*=(const ModInt &p) {
x = (int)(1ll * x * p.x % mod);
return *this;
}
ModInt &operator/=(const ModInt &p) {
*this *= p.inverse();
return *this;
}
ModInt operator-() const {return ModInt(-x);}
ModInt operator+(const ModInt &p) const { return ModInt(*this) += p; }
ModInt operator-(const ModInt &p) const { return ModInt(*this) -= p; }
ModInt operator*(const ModInt &p) const { return ModInt(*this) *= p; }
ModInt operator/(const ModInt &p) const { return ModInt(*this) /= p; }
bool operator==(const ModInt& p) const {return x == p.x; }
bool operator!=(const ModInt& p) const {return x != p.x; }
ModInt inverse() const {
int a = x, b = mod, u = 1, v = 0, t;
while(b > 0) {
t = a / b;
swap(a -= t * b, b);
swap(u -= t * v, v);
}
return ModInt(u);
}
ModInt pow(int64_t n) const {
ModInt ret(1), mul(x);
while(n > 0) {
if(n & 1) ret *= mul;
mul *= mul;
n >>= 1;
}
return ret;
}
friend ostream &operator<<(ostream &os, const ModInt &p) { return os << p.x; }
};
const int MOD = 1e9 + 7;
int main() {
int64 N, K; cin >> N >> K;
int64 sum = 0;
int64 ans = 0;
while(true) {
int64 res = ceil(1.0 * (N - sum) / (K + 1));
ans++;
sum += res;
if(N - sum == 0) break;
}
cout << ans << endl;
}
| CPP |
p00389 Pilling Blocks | We make a tower by stacking up blocks. The tower consists of several stages and each stage is constructed by connecting blocks horizontally. Each block is of the same weight and is tough enough to withstand the weight equivalent to up to $K$ blocks without crushing.
We have to build the tower abiding by the following conditions:
* Every stage of the tower has one or more blocks on it.
* Each block is loaded with weight that falls within the withstanding range of the block. The weight loaded on a block in a stage is evaluated by: total weight of all blocks above the stage divided by the number of blocks within the stage.
Given the number of blocks and the strength, make a program to evaluate the maximum height (i.e., stages) of the tower than can be constructed.
Input
The input is given in the following format.
$N$ $K$
The input line provides the number of blocks available $N$ ($1 \leq N \leq 10^5$) and the strength of the block $K$ ($1 \leq K \leq 10^5$).
Output
Output the maximum possible number of stages.
Examples
Input
4 2
Output
3
Input
5 2
Output
4 | 7 | 0 | N,K = map(int, input().split())
t = n = a = 1
while True:
n = (K+a-1)//K
a += n;
if N < a: break
t += 1
print(t)
| PYTHON3 |
p00389 Pilling Blocks | We make a tower by stacking up blocks. The tower consists of several stages and each stage is constructed by connecting blocks horizontally. Each block is of the same weight and is tough enough to withstand the weight equivalent to up to $K$ blocks without crushing.
We have to build the tower abiding by the following conditions:
* Every stage of the tower has one or more blocks on it.
* Each block is loaded with weight that falls within the withstanding range of the block. The weight loaded on a block in a stage is evaluated by: total weight of all blocks above the stage divided by the number of blocks within the stage.
Given the number of blocks and the strength, make a program to evaluate the maximum height (i.e., stages) of the tower than can be constructed.
Input
The input is given in the following format.
$N$ $K$
The input line provides the number of blocks available $N$ ($1 \leq N \leq 10^5$) and the strength of the block $K$ ($1 \leq K \leq 10^5$).
Output
Output the maximum possible number of stages.
Examples
Input
4 2
Output
3
Input
5 2
Output
4 | 7 | 0 | #include<bits/stdc++.h>
using namespace std;
int main(){
int N, K;
cin >> N >> K;
int n = N;
int sum = 0;
int ans = 0;
while (n >= 0) {
int row = (sum + K - 1) / K;
row = max(row, 1);
// cout << n << " " << sum << " " << ans << " " << row << endl;
if (row > n)
break;
else {
ans++;
n -= row;
sum += row;
}
}
cout << ans << endl;
return 0;
}
| CPP |
p00389 Pilling Blocks | We make a tower by stacking up blocks. The tower consists of several stages and each stage is constructed by connecting blocks horizontally. Each block is of the same weight and is tough enough to withstand the weight equivalent to up to $K$ blocks without crushing.
We have to build the tower abiding by the following conditions:
* Every stage of the tower has one or more blocks on it.
* Each block is loaded with weight that falls within the withstanding range of the block. The weight loaded on a block in a stage is evaluated by: total weight of all blocks above the stage divided by the number of blocks within the stage.
Given the number of blocks and the strength, make a program to evaluate the maximum height (i.e., stages) of the tower than can be constructed.
Input
The input is given in the following format.
$N$ $K$
The input line provides the number of blocks available $N$ ($1 \leq N \leq 10^5$) and the strength of the block $K$ ($1 \leq K \leq 10^5$).
Output
Output the maximum possible number of stages.
Examples
Input
4 2
Output
3
Input
5 2
Output
4 | 7 | 0 | #include <iostream>
#include <algorithm>
using namespace std;
class Solver {
public:
static void solve() {
int n, k;
cin >> n >> k;
int now = 1;
n--;
int sum = 1;
while (true) {
int need = sum / k;
if (sum % k > 0)need++;
if (n < need)break;
now++;
sum += need;
n -= need;
}
cout << now << endl;
}
};
int main() {
Solver::solve();
}
| CPP |
p00389 Pilling Blocks | We make a tower by stacking up blocks. The tower consists of several stages and each stage is constructed by connecting blocks horizontally. Each block is of the same weight and is tough enough to withstand the weight equivalent to up to $K$ blocks without crushing.
We have to build the tower abiding by the following conditions:
* Every stage of the tower has one or more blocks on it.
* Each block is loaded with weight that falls within the withstanding range of the block. The weight loaded on a block in a stage is evaluated by: total weight of all blocks above the stage divided by the number of blocks within the stage.
Given the number of blocks and the strength, make a program to evaluate the maximum height (i.e., stages) of the tower than can be constructed.
Input
The input is given in the following format.
$N$ $K$
The input line provides the number of blocks available $N$ ($1 \leq N \leq 10^5$) and the strength of the block $K$ ($1 \leq K \leq 10^5$).
Output
Output the maximum possible number of stages.
Examples
Input
4 2
Output
3
Input
5 2
Output
4 | 7 | 0 | import java.util.*;
public class Main {
public static void main (String[] args) {
Scanner sc = new Scanner(System.in);
int count = sc.nextInt();
int strength = sc.nextInt();
int total = 1;
int size = 1;
count--;
while (true) {
int x = (total + strength - 1) / strength;
if (count >= x) {
size++;
total += x;
count -= x;
} else {
break;
}
}
System.out.println(size);
}
}
| JAVA |
p00389 Pilling Blocks | We make a tower by stacking up blocks. The tower consists of several stages and each stage is constructed by connecting blocks horizontally. Each block is of the same weight and is tough enough to withstand the weight equivalent to up to $K$ blocks without crushing.
We have to build the tower abiding by the following conditions:
* Every stage of the tower has one or more blocks on it.
* Each block is loaded with weight that falls within the withstanding range of the block. The weight loaded on a block in a stage is evaluated by: total weight of all blocks above the stage divided by the number of blocks within the stage.
Given the number of blocks and the strength, make a program to evaluate the maximum height (i.e., stages) of the tower than can be constructed.
Input
The input is given in the following format.
$N$ $K$
The input line provides the number of blocks available $N$ ($1 \leq N \leq 10^5$) and the strength of the block $K$ ($1 \leq K \leq 10^5$).
Output
Output the maximum possible number of stages.
Examples
Input
4 2
Output
3
Input
5 2
Output
4 | 7 | 0 | #include <iostream>
using namespace std;
int main(void)
{
int N, K;
cin >> N >> K;
int cnt = 0;
while(N>0){
int x = (N-1)/(K+1)+1;
N -= x;
cnt++;
}
cout << cnt << endl;
}
| CPP |
p00389 Pilling Blocks | We make a tower by stacking up blocks. The tower consists of several stages and each stage is constructed by connecting blocks horizontally. Each block is of the same weight and is tough enough to withstand the weight equivalent to up to $K$ blocks without crushing.
We have to build the tower abiding by the following conditions:
* Every stage of the tower has one or more blocks on it.
* Each block is loaded with weight that falls within the withstanding range of the block. The weight loaded on a block in a stage is evaluated by: total weight of all blocks above the stage divided by the number of blocks within the stage.
Given the number of blocks and the strength, make a program to evaluate the maximum height (i.e., stages) of the tower than can be constructed.
Input
The input is given in the following format.
$N$ $K$
The input line provides the number of blocks available $N$ ($1 \leq N \leq 10^5$) and the strength of the block $K$ ($1 \leq K \leq 10^5$).
Output
Output the maximum possible number of stages.
Examples
Input
4 2
Output
3
Input
5 2
Output
4 | 7 | 0 | n, k = map(int, input().split())
ans = 1
w = 1
while n-w>0:
blw = (w+k-1)//k
w += blw
if n-w>=0: ans+=1
print(ans)
| PYTHON3 |
p00389 Pilling Blocks | We make a tower by stacking up blocks. The tower consists of several stages and each stage is constructed by connecting blocks horizontally. Each block is of the same weight and is tough enough to withstand the weight equivalent to up to $K$ blocks without crushing.
We have to build the tower abiding by the following conditions:
* Every stage of the tower has one or more blocks on it.
* Each block is loaded with weight that falls within the withstanding range of the block. The weight loaded on a block in a stage is evaluated by: total weight of all blocks above the stage divided by the number of blocks within the stage.
Given the number of blocks and the strength, make a program to evaluate the maximum height (i.e., stages) of the tower than can be constructed.
Input
The input is given in the following format.
$N$ $K$
The input line provides the number of blocks available $N$ ($1 \leq N \leq 10^5$) and the strength of the block $K$ ($1 \leq K \leq 10^5$).
Output
Output the maximum possible number of stages.
Examples
Input
4 2
Output
3
Input
5 2
Output
4 | 7 | 0 | #include<bits/stdc++.h>
using namespace std;
int main(void){
int n, k;
cin >> n >> k;
int x = 1, y = 0, sum = 0;
while(1){
if(sum + x > n) break;
if(sum > k * x){
x = sum / k;
if(sum % k > 0) x++;
}
else sum += x, y++;
}
cout << y << endl;
return 0;
}
| CPP |
p00389 Pilling Blocks | We make a tower by stacking up blocks. The tower consists of several stages and each stage is constructed by connecting blocks horizontally. Each block is of the same weight and is tough enough to withstand the weight equivalent to up to $K$ blocks without crushing.
We have to build the tower abiding by the following conditions:
* Every stage of the tower has one or more blocks on it.
* Each block is loaded with weight that falls within the withstanding range of the block. The weight loaded on a block in a stage is evaluated by: total weight of all blocks above the stage divided by the number of blocks within the stage.
Given the number of blocks and the strength, make a program to evaluate the maximum height (i.e., stages) of the tower than can be constructed.
Input
The input is given in the following format.
$N$ $K$
The input line provides the number of blocks available $N$ ($1 \leq N \leq 10^5$) and the strength of the block $K$ ($1 \leq K \leq 10^5$).
Output
Output the maximum possible number of stages.
Examples
Input
4 2
Output
3
Input
5 2
Output
4 | 7 | 0 | #include <iostream>
#include <string>
#include <algorithm>
#include <functional>
#include <vector>
#include <utility>
#include <cstring>
#include <iomanip>
#include <numeric>
#include <cmath>
#include <queue>
#include <map>
using namespace std;
typedef long long ll;
const int INF = 1<<30;
const int MOD = 1e9 + 7;
const int dy[] = {1, 0, -1, 0};
const int dx[] = {0, 1, 0, -1};
int main()
{
cin.tie(0);
ios::sync_with_stdio(false);
int n, k; cin >> n >> k;
int total = 0, now = 1;
int ans = 0;
while(n > 0)
{
while((total + now - 1) / now > k) now++;
if(n - now < 0) break;
total += now;
n -= now;
ans++;
}
cout << ans << endl;
return 0;
}
| CPP |
p00389 Pilling Blocks | We make a tower by stacking up blocks. The tower consists of several stages and each stage is constructed by connecting blocks horizontally. Each block is of the same weight and is tough enough to withstand the weight equivalent to up to $K$ blocks without crushing.
We have to build the tower abiding by the following conditions:
* Every stage of the tower has one or more blocks on it.
* Each block is loaded with weight that falls within the withstanding range of the block. The weight loaded on a block in a stage is evaluated by: total weight of all blocks above the stage divided by the number of blocks within the stage.
Given the number of blocks and the strength, make a program to evaluate the maximum height (i.e., stages) of the tower than can be constructed.
Input
The input is given in the following format.
$N$ $K$
The input line provides the number of blocks available $N$ ($1 \leq N \leq 10^5$) and the strength of the block $K$ ($1 \leq K \leq 10^5$).
Output
Output the maximum possible number of stages.
Examples
Input
4 2
Output
3
Input
5 2
Output
4 | 7 | 0 | #include <bits/stdc++.h>
using namespace std;
#define INCANT cin.tie(0), cout.tie(0), ios::sync_with_stdio(false), cout << fixed << setprecision(20);
#define int long long
#define gcd __gcd
#define all(x) (x).begin(), (x).end()
const int INF = 1e18, MOD = 1e9 + 7;
template<class T>
bool chmax(T& a, T b){return (a = max(a, b)) == b;}
template<class T>
bool chmin(T& a, T b){return (a = min(a, b)) == b;}
#define _overload(_1, _2, _3, name, ...) name
#define _rep(i, n) repi(i, 0, n)
#define repi(i, a, b) for(int i = (int)(a); i < (int)(b); i++)
#define rep(...) _overload(__VA_ARGS__, repi, _rep)(__VA_ARGS__)
#define _rev(i, n) revi(i, n, 0)
#define revi(i, a, b) for(int i = (int)(a - 1); i >= (int)(b); i--)
#define rev(...) _overload(__VA_ARGS__, revi, _rev)(__VA_ARGS__)
#define each(i, n) for(auto&& i: n)
signed main() {
INCANT;
int n, k, cnt = 1, res = 0, mass = 0;
cin>>n>>k;
while(n>=0){
if((mass + cnt - 1)/ cnt <= k){
mass += cnt;
n -= cnt;
res++;
}else{
cnt++;
}
}
cout<<--res<<endl;
}
| CPP |
p00389 Pilling Blocks | We make a tower by stacking up blocks. The tower consists of several stages and each stage is constructed by connecting blocks horizontally. Each block is of the same weight and is tough enough to withstand the weight equivalent to up to $K$ blocks without crushing.
We have to build the tower abiding by the following conditions:
* Every stage of the tower has one or more blocks on it.
* Each block is loaded with weight that falls within the withstanding range of the block. The weight loaded on a block in a stage is evaluated by: total weight of all blocks above the stage divided by the number of blocks within the stage.
Given the number of blocks and the strength, make a program to evaluate the maximum height (i.e., stages) of the tower than can be constructed.
Input
The input is given in the following format.
$N$ $K$
The input line provides the number of blocks available $N$ ($1 \leq N \leq 10^5$) and the strength of the block $K$ ($1 \leq K \leq 10^5$).
Output
Output the maximum possible number of stages.
Examples
Input
4 2
Output
3
Input
5 2
Output
4 | 7 | 0 | #include <bits/stdc++.h>
using namespace std;
int main(){
int n,k,sum=0,now=1,ans=0;
cin>>n>>k;
for(;;){
if(sum+now>n)break;
else if(sum<=now*k)sum+=now,ans++;
else now++;
}
cout<<ans<<endl;
}
| CPP |
p00389 Pilling Blocks | We make a tower by stacking up blocks. The tower consists of several stages and each stage is constructed by connecting blocks horizontally. Each block is of the same weight and is tough enough to withstand the weight equivalent to up to $K$ blocks without crushing.
We have to build the tower abiding by the following conditions:
* Every stage of the tower has one or more blocks on it.
* Each block is loaded with weight that falls within the withstanding range of the block. The weight loaded on a block in a stage is evaluated by: total weight of all blocks above the stage divided by the number of blocks within the stage.
Given the number of blocks and the strength, make a program to evaluate the maximum height (i.e., stages) of the tower than can be constructed.
Input
The input is given in the following format.
$N$ $K$
The input line provides the number of blocks available $N$ ($1 \leq N \leq 10^5$) and the strength of the block $K$ ($1 \leq K \leq 10^5$).
Output
Output the maximum possible number of stages.
Examples
Input
4 2
Output
3
Input
5 2
Output
4 | 7 | 0 | #include <bits/stdc++.h>
using namespace std;
using ll = long long;
int main() {
ll n, k; cin >> n >> k;
int ans = 0, sum = 0;
while(n >= max(1LL, (sum + k - 1) / k)) {
ans += 1;
const ll add = max(1LL, (sum + k - 1) / k);
sum += add;
n -= add;
}
cout << ans << endl;
}
| CPP |
p00389 Pilling Blocks | We make a tower by stacking up blocks. The tower consists of several stages and each stage is constructed by connecting blocks horizontally. Each block is of the same weight and is tough enough to withstand the weight equivalent to up to $K$ blocks without crushing.
We have to build the tower abiding by the following conditions:
* Every stage of the tower has one or more blocks on it.
* Each block is loaded with weight that falls within the withstanding range of the block. The weight loaded on a block in a stage is evaluated by: total weight of all blocks above the stage divided by the number of blocks within the stage.
Given the number of blocks and the strength, make a program to evaluate the maximum height (i.e., stages) of the tower than can be constructed.
Input
The input is given in the following format.
$N$ $K$
The input line provides the number of blocks available $N$ ($1 \leq N \leq 10^5$) and the strength of the block $K$ ($1 \leq K \leq 10^5$).
Output
Output the maximum possible number of stages.
Examples
Input
4 2
Output
3
Input
5 2
Output
4 | 7 | 0 | #include<bits/stdc++.h>
using namespace std;
#define rep(i,x,y) for(int i=x;i<y;i++)
#define print(a,n) rep(i,0,n){ cout<<(i ? " ":"")<<a[i]; }cout<<endl;
#define pprint(a,m,n) rep(j,0,m){ print(a[j],n); }
const int mod = 1e9+7;
const int size=1e5;
const int INF=1e9;
int main(){
int N,K;cin>>N>>K;
int sum=1;int i=1;
int temp;
while(sum<N){
temp=(sum+K-1)/K;//cout<<temp<<endl;
if(N-sum>=temp){ sum+=temp; i++; }
else break;
}cout<<i<<endl;
return 0;
}
| CPP |
p00389 Pilling Blocks | We make a tower by stacking up blocks. The tower consists of several stages and each stage is constructed by connecting blocks horizontally. Each block is of the same weight and is tough enough to withstand the weight equivalent to up to $K$ blocks without crushing.
We have to build the tower abiding by the following conditions:
* Every stage of the tower has one or more blocks on it.
* Each block is loaded with weight that falls within the withstanding range of the block. The weight loaded on a block in a stage is evaluated by: total weight of all blocks above the stage divided by the number of blocks within the stage.
Given the number of blocks and the strength, make a program to evaluate the maximum height (i.e., stages) of the tower than can be constructed.
Input
The input is given in the following format.
$N$ $K$
The input line provides the number of blocks available $N$ ($1 \leq N \leq 10^5$) and the strength of the block $K$ ($1 \leq K \leq 10^5$).
Output
Output the maximum possible number of stages.
Examples
Input
4 2
Output
3
Input
5 2
Output
4 | 7 | 0 | #include <iostream>
#include <algorithm>
#include <vector>
using namespace std;
int judge(int n,int k,int amari){
if(amari<=1){
return 0;
} else {
for(double i=2;;i++){
if((n-amari)/i<=k) return i;
if(amari<=i) return 0;
}
}
}
int main(){
int n,k;
cin >> n >> k;
int num=k+1;
int amari=n-num;
for(;;){
if(n<=k){
num = n;
break;
} else if(n==k){
num=n;
break;
} else if(judge(n,k,amari)==0){
break;
} else{
num++;
amari-=judge(n,k,amari);
}
}
cout << num << endl;
return 0;
}
| CPP |
p00389 Pilling Blocks | We make a tower by stacking up blocks. The tower consists of several stages and each stage is constructed by connecting blocks horizontally. Each block is of the same weight and is tough enough to withstand the weight equivalent to up to $K$ blocks without crushing.
We have to build the tower abiding by the following conditions:
* Every stage of the tower has one or more blocks on it.
* Each block is loaded with weight that falls within the withstanding range of the block. The weight loaded on a block in a stage is evaluated by: total weight of all blocks above the stage divided by the number of blocks within the stage.
Given the number of blocks and the strength, make a program to evaluate the maximum height (i.e., stages) of the tower than can be constructed.
Input
The input is given in the following format.
$N$ $K$
The input line provides the number of blocks available $N$ ($1 \leq N \leq 10^5$) and the strength of the block $K$ ($1 \leq K \leq 10^5$).
Output
Output the maximum possible number of stages.
Examples
Input
4 2
Output
3
Input
5 2
Output
4 | 7 | 0 | #include <iostream>
using namespace std;
int putBlocks(int N, int K)
{
if (N == 1) return 1;
else {
int most_under = 1;//最下段のブロックの数
int count = N;//注目塔の高さ
while ((((double)count - 1) / (double)most_under) > K) {//注目塔の最下段の強度を判定
most_under++;
count--;//塔の高さを減らす(最下段へ)
}
return 1 + putBlocks(count - 1,K);//注目塔の最下段を1つ上にずらして返却
}
}
int main()
{
int N, K;
cin >> N >> K;
cout << putBlocks(N, K) << endl;
return 0;
}
| CPP |
p00389 Pilling Blocks | We make a tower by stacking up blocks. The tower consists of several stages and each stage is constructed by connecting blocks horizontally. Each block is of the same weight and is tough enough to withstand the weight equivalent to up to $K$ blocks without crushing.
We have to build the tower abiding by the following conditions:
* Every stage of the tower has one or more blocks on it.
* Each block is loaded with weight that falls within the withstanding range of the block. The weight loaded on a block in a stage is evaluated by: total weight of all blocks above the stage divided by the number of blocks within the stage.
Given the number of blocks and the strength, make a program to evaluate the maximum height (i.e., stages) of the tower than can be constructed.
Input
The input is given in the following format.
$N$ $K$
The input line provides the number of blocks available $N$ ($1 \leq N \leq 10^5$) and the strength of the block $K$ ($1 \leq K \leq 10^5$).
Output
Output the maximum possible number of stages.
Examples
Input
4 2
Output
3
Input
5 2
Output
4 | 7 | 0 | #include "bits/stdc++.h"
using namespace std;
int main() {
long long N, K, NOW = 1, ANS = 0;
cin >> N >> K;
while (N >= NOW) {
NOW += (NOW + K - 1) / K;
ANS++;
}
cout << ANS << endl;
}
| CPP |
p00389 Pilling Blocks | We make a tower by stacking up blocks. The tower consists of several stages and each stage is constructed by connecting blocks horizontally. Each block is of the same weight and is tough enough to withstand the weight equivalent to up to $K$ blocks without crushing.
We have to build the tower abiding by the following conditions:
* Every stage of the tower has one or more blocks on it.
* Each block is loaded with weight that falls within the withstanding range of the block. The weight loaded on a block in a stage is evaluated by: total weight of all blocks above the stage divided by the number of blocks within the stage.
Given the number of blocks and the strength, make a program to evaluate the maximum height (i.e., stages) of the tower than can be constructed.
Input
The input is given in the following format.
$N$ $K$
The input line provides the number of blocks available $N$ ($1 \leq N \leq 10^5$) and the strength of the block $K$ ($1 \leq K \leq 10^5$).
Output
Output the maximum possible number of stages.
Examples
Input
4 2
Output
3
Input
5 2
Output
4 | 7 | 0 | #include<bits/stdc++.h>
using namespace std;
using Int = long long;
template<typename T1,typename T2> inline void chmin(T1 &a,T2 b){if(a>b) a=b;}
template<typename T1,typename T2> inline void chmax(T1 &a,T2 b){if(a<b) a=b;}
//INSERT ABOVE HERE
signed main(){
Int n,k;
cin>>n>>k;
Int ans=1,sum=1;
n--;
while(1){
Int x=(sum+k-1)/k;
if(x>n) break;
n-=x;
sum+=x;
ans++;
}
cout<<ans<<endl;
return 0;
}
| CPP |
p00389 Pilling Blocks | We make a tower by stacking up blocks. The tower consists of several stages and each stage is constructed by connecting blocks horizontally. Each block is of the same weight and is tough enough to withstand the weight equivalent to up to $K$ blocks without crushing.
We have to build the tower abiding by the following conditions:
* Every stage of the tower has one or more blocks on it.
* Each block is loaded with weight that falls within the withstanding range of the block. The weight loaded on a block in a stage is evaluated by: total weight of all blocks above the stage divided by the number of blocks within the stage.
Given the number of blocks and the strength, make a program to evaluate the maximum height (i.e., stages) of the tower than can be constructed.
Input
The input is given in the following format.
$N$ $K$
The input line provides the number of blocks available $N$ ($1 \leq N \leq 10^5$) and the strength of the block $K$ ($1 \leq K \leq 10^5$).
Output
Output the maximum possible number of stages.
Examples
Input
4 2
Output
3
Input
5 2
Output
4 | 7 | 0 | #include <bits/stdc++.h>
using LL = long long;
using namespace std;
int main(){
int N,K;cin >> N >> K;
LL ans = 1;
LL weight = 1;
LL ins = 0;
N--;
while(N != 0){
// cout<<weight<<endl;
if(ins == 0){
ins++;
N--;
}else
if(1.0*weight/ins <= K){
weight += ins;
ins = 0;
ans++;
}else{
ins++;
N--;
}
}
cout<<ans + (1.0*weight/ins <= K?1:0)<<endl;
}
| CPP |
p00389 Pilling Blocks | We make a tower by stacking up blocks. The tower consists of several stages and each stage is constructed by connecting blocks horizontally. Each block is of the same weight and is tough enough to withstand the weight equivalent to up to $K$ blocks without crushing.
We have to build the tower abiding by the following conditions:
* Every stage of the tower has one or more blocks on it.
* Each block is loaded with weight that falls within the withstanding range of the block. The weight loaded on a block in a stage is evaluated by: total weight of all blocks above the stage divided by the number of blocks within the stage.
Given the number of blocks and the strength, make a program to evaluate the maximum height (i.e., stages) of the tower than can be constructed.
Input
The input is given in the following format.
$N$ $K$
The input line provides the number of blocks available $N$ ($1 \leq N \leq 10^5$) and the strength of the block $K$ ($1 \leq K \leq 10^5$).
Output
Output the maximum possible number of stages.
Examples
Input
4 2
Output
3
Input
5 2
Output
4 | 7 | 0 | #define _AOJ_
#include "bits/stdc++.h"
using namespace std;
typedef long long i64;
#define rep(i,n) for(int i=0;i<n;++i)
#define REP(i,a,b) for(int i=a;i<b;++i)
#define all(c) c.begin(),c.end()
//define pfs,bellmanford,etc.
int main(){
i64 n,k;cin>>n>>k;
i64 s=1,ans=1;
vector<i64>a(1,1);
while(s<=n){
a.push_back((s+k-1)/k);
s+=a.back();
if(s<=n)ans=a.size();
}
cout<<ans<<endl;
}
//sub-EOF
| CPP |
p00389 Pilling Blocks | We make a tower by stacking up blocks. The tower consists of several stages and each stage is constructed by connecting blocks horizontally. Each block is of the same weight and is tough enough to withstand the weight equivalent to up to $K$ blocks without crushing.
We have to build the tower abiding by the following conditions:
* Every stage of the tower has one or more blocks on it.
* Each block is loaded with weight that falls within the withstanding range of the block. The weight loaded on a block in a stage is evaluated by: total weight of all blocks above the stage divided by the number of blocks within the stage.
Given the number of blocks and the strength, make a program to evaluate the maximum height (i.e., stages) of the tower than can be constructed.
Input
The input is given in the following format.
$N$ $K$
The input line provides the number of blocks available $N$ ($1 \leq N \leq 10^5$) and the strength of the block $K$ ($1 \leq K \leq 10^5$).
Output
Output the maximum possible number of stages.
Examples
Input
4 2
Output
3
Input
5 2
Output
4 | 7 | 0 | #include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int (i)=0;(i)<(n);(i)++)
int main() {
int n,k,t=0,ans=0,u=1;
cin >> n >> k;
while (true) {
if (n-t<u) break;
if (u*k>=t) {t+=u;ans++;}
else {u++;continue;}
}
cout << ans << endl;
}
| CPP |
p00389 Pilling Blocks | We make a tower by stacking up blocks. The tower consists of several stages and each stage is constructed by connecting blocks horizontally. Each block is of the same weight and is tough enough to withstand the weight equivalent to up to $K$ blocks without crushing.
We have to build the tower abiding by the following conditions:
* Every stage of the tower has one or more blocks on it.
* Each block is loaded with weight that falls within the withstanding range of the block. The weight loaded on a block in a stage is evaluated by: total weight of all blocks above the stage divided by the number of blocks within the stage.
Given the number of blocks and the strength, make a program to evaluate the maximum height (i.e., stages) of the tower than can be constructed.
Input
The input is given in the following format.
$N$ $K$
The input line provides the number of blocks available $N$ ($1 \leq N \leq 10^5$) and the strength of the block $K$ ($1 \leq K \leq 10^5$).
Output
Output the maximum possible number of stages.
Examples
Input
4 2
Output
3
Input
5 2
Output
4 | 7 | 0 | import math
n, k = map(int, input().split())
ret = 1
acc = 1
while True:
want = math.ceil(acc / k)
if(want+acc > n):
break
acc += want
ret += 1
print(ret)
| PYTHON3 |
p00389 Pilling Blocks | We make a tower by stacking up blocks. The tower consists of several stages and each stage is constructed by connecting blocks horizontally. Each block is of the same weight and is tough enough to withstand the weight equivalent to up to $K$ blocks without crushing.
We have to build the tower abiding by the following conditions:
* Every stage of the tower has one or more blocks on it.
* Each block is loaded with weight that falls within the withstanding range of the block. The weight loaded on a block in a stage is evaluated by: total weight of all blocks above the stage divided by the number of blocks within the stage.
Given the number of blocks and the strength, make a program to evaluate the maximum height (i.e., stages) of the tower than can be constructed.
Input
The input is given in the following format.
$N$ $K$
The input line provides the number of blocks available $N$ ($1 \leq N \leq 10^5$) and the strength of the block $K$ ($1 \leq K \leq 10^5$).
Output
Output the maximum possible number of stages.
Examples
Input
4 2
Output
3
Input
5 2
Output
4 | 7 | 0 | #include<bits/stdc++.h>
using namespace std;
typedef long long int ll;
typedef pair<ll,ll> mp;
#define inf 1e9
int main(){
int n,k;
cin>>n>>k;
int sum = 0;
int h = 0;
int y = 1;
while(n-y>=0){
// cout<<n<<endl;
if((double)sum/y <= k){
sum+=y;
n-=y;
h++;
}else{
while( ( (double) sum/y) > (double)k){
y++;
// cout<<y<<' '<<k<<endl;
}
n-=y;
if(n < 0) break;
sum+=y;
h++;
}
}
cout<<h<<endl;
return 0;
}
| CPP |
p00389 Pilling Blocks | We make a tower by stacking up blocks. The tower consists of several stages and each stage is constructed by connecting blocks horizontally. Each block is of the same weight and is tough enough to withstand the weight equivalent to up to $K$ blocks without crushing.
We have to build the tower abiding by the following conditions:
* Every stage of the tower has one or more blocks on it.
* Each block is loaded with weight that falls within the withstanding range of the block. The weight loaded on a block in a stage is evaluated by: total weight of all blocks above the stage divided by the number of blocks within the stage.
Given the number of blocks and the strength, make a program to evaluate the maximum height (i.e., stages) of the tower than can be constructed.
Input
The input is given in the following format.
$N$ $K$
The input line provides the number of blocks available $N$ ($1 \leq N \leq 10^5$) and the strength of the block $K$ ($1 \leq K \leq 10^5$).
Output
Output the maximum possible number of stages.
Examples
Input
4 2
Output
3
Input
5 2
Output
4 | 7 | 0 | #include <bits/stdc++.h>
#define rep(i,n)for(int i=0;i<(n);i++)
using namespace std;
typedef long long ll;
typedef pair<int,int>P;
int main(){
int n,K;cin>>n>>K;
int cnt=1,i=1;
for(;;i++){
int need=(cnt+K-1)/K;
if(cnt+need>n)break;
cnt+=need;
}
cout<<i<<endl;
}
| CPP |
p00389 Pilling Blocks | We make a tower by stacking up blocks. The tower consists of several stages and each stage is constructed by connecting blocks horizontally. Each block is of the same weight and is tough enough to withstand the weight equivalent to up to $K$ blocks without crushing.
We have to build the tower abiding by the following conditions:
* Every stage of the tower has one or more blocks on it.
* Each block is loaded with weight that falls within the withstanding range of the block. The weight loaded on a block in a stage is evaluated by: total weight of all blocks above the stage divided by the number of blocks within the stage.
Given the number of blocks and the strength, make a program to evaluate the maximum height (i.e., stages) of the tower than can be constructed.
Input
The input is given in the following format.
$N$ $K$
The input line provides the number of blocks available $N$ ($1 \leq N \leq 10^5$) and the strength of the block $K$ ($1 \leq K \leq 10^5$).
Output
Output the maximum possible number of stages.
Examples
Input
4 2
Output
3
Input
5 2
Output
4 | 7 | 0 | #include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef pair<int, ll> pil;
typedef pair<int, ll> pli;
typedef pair<double,double> pdd;
#define SQ(i) ((i)*(i))
#define MEM(a, b) memset(a, (b), sizeof(a))
#define SZ(i) int(i.size())
#define FOR(i, j, k, in) for (int i=j ; i<k ; i+=in)
#define RFOR(i, j, k, in) for (int i=j ; i>=k ; i-=in)
#define REP(i, j) FOR(i, 0, j, 1)
#define REP1(i,j) FOR(i, 1, j+1, 1)
#define RREP(i, j) RFOR(i, j, 0, 1)
#define ALL(_a) _a.begin(),_a.end()
#define mp make_pair
#define pb push_back
#define eb emplace_back
#define X first
#define Y second
#ifdef tmd
#define TIME(i) Timer i(#i)
#define debug(...) do{\
fprintf(stderr,"%s - %d (%s) = ",__PRETTY_FUNCTION__,__LINE__,#__VA_ARGS__);\
_do(__VA_ARGS__);\
}while(0)
template<typename T>void _do(T &&_x){cerr<<_x<<endl;}
template<typename T,typename ...S> void _do(T &&_x,S &&..._t){cerr<<_x<<" ,";_do(_t...);}
template<typename _a,typename _b> ostream& operator << (ostream &_s,const pair<_a,_b> &_p){return _s<<"("<<_p.X<<","<<_p.Y<<")";}
template<typename It> ostream& _OUTC(ostream &_s,It _ita,It _itb)
{
_s<<"{";
for(It _it=_ita;_it!=_itb;_it++)
{
_s<<(_it==_ita?"":",")<<*_it;
}
_s<<"}";
return _s;
}
template<typename _a> ostream &operator << (ostream &_s,vector<_a> &_c){return _OUTC(_s,ALL(_c));}
template<typename _a> ostream &operator << (ostream &_s,set<_a> &_c){return _OUTC(_s,ALL(_c));}
template<typename _a> ostream &operator << (ostream &_s,deque<_a> &_c){return _OUTC(_s,ALL(_c));}
template<typename _a,typename _b> ostream &operator << (ostream &_s,map<_a,_b> &_c){return _OUTC(_s,ALL(_c));}
template<typename _t> void pary(_t _a,_t _b){_OUTC(cerr,_a,_b);cerr<<endl;}
#define IOS()
class Timer {
private:
string scope_name;
chrono::high_resolution_clock::time_point start_time;
public:
Timer (string name) : scope_name(name) {
start_time = chrono::high_resolution_clock::now();
}
~Timer () {
auto stop_time = chrono::high_resolution_clock::now();
auto length = chrono::duration_cast<chrono::microseconds>(stop_time - start_time).count();
double mlength = double(length) * 0.001;
debug(scope_name, mlength);
}
};
#else
#define TIME(i)
#define debug(...)
#define pary(...)
#define endl '\n'
#define IOS() ios_base::sync_with_stdio(0);cin.tie(0)
#endif
const ll MOD = 1000000007;
const ll INF = 0x3f3f3f3f3f3f3f3f;
const int iNF = 0x3f3f3f3f;
// const ll MAXN =
int n, k;
/********** Good Luck :) **********/
int main () {
TIME(main);
IOS();
cin >> n >> k;
int sum = 0, ans = 0;
while (true) {
int cur = max(1, (sum+k-1)/k);
debug(cur);
if (n < cur) {
break;
} else {
n -= cur;
sum += cur;
ans++;
}
}
cout << ans << endl;
return 0;
}
| CPP |
p00389 Pilling Blocks | We make a tower by stacking up blocks. The tower consists of several stages and each stage is constructed by connecting blocks horizontally. Each block is of the same weight and is tough enough to withstand the weight equivalent to up to $K$ blocks without crushing.
We have to build the tower abiding by the following conditions:
* Every stage of the tower has one or more blocks on it.
* Each block is loaded with weight that falls within the withstanding range of the block. The weight loaded on a block in a stage is evaluated by: total weight of all blocks above the stage divided by the number of blocks within the stage.
Given the number of blocks and the strength, make a program to evaluate the maximum height (i.e., stages) of the tower than can be constructed.
Input
The input is given in the following format.
$N$ $K$
The input line provides the number of blocks available $N$ ($1 \leq N \leq 10^5$) and the strength of the block $K$ ($1 \leq K \leq 10^5$).
Output
Output the maximum possible number of stages.
Examples
Input
4 2
Output
3
Input
5 2
Output
4 | 7 | 0 | #include<iostream>
using namespace std;
int main(){
int N, K, count = 0, sum = 0, num = 1;
cin>>N>>K;
for(;;){
if(sum > num*K){
num = (sum+K-1)/K;
//cout<<"num = "<<num<<endl;
}
N -= num;
sum += num;
if(N < 0)break;
count++;
//cout<<count<<" "<<sum<<" "<<num<<endl;
}
cout<<count<<endl;
return 0;
}
| CPP |
p00389 Pilling Blocks | We make a tower by stacking up blocks. The tower consists of several stages and each stage is constructed by connecting blocks horizontally. Each block is of the same weight and is tough enough to withstand the weight equivalent to up to $K$ blocks without crushing.
We have to build the tower abiding by the following conditions:
* Every stage of the tower has one or more blocks on it.
* Each block is loaded with weight that falls within the withstanding range of the block. The weight loaded on a block in a stage is evaluated by: total weight of all blocks above the stage divided by the number of blocks within the stage.
Given the number of blocks and the strength, make a program to evaluate the maximum height (i.e., stages) of the tower than can be constructed.
Input
The input is given in the following format.
$N$ $K$
The input line provides the number of blocks available $N$ ($1 \leq N \leq 10^5$) and the strength of the block $K$ ($1 \leq K \leq 10^5$).
Output
Output the maximum possible number of stages.
Examples
Input
4 2
Output
3
Input
5 2
Output
4 | 7 | 0 | #include<bits/stdc++.h>
using namespace std;
int main(){
int N ,K;
cin >> N >> K;
int ans = 1;
int wei = 1;
N--;
while(N > 0){
int n = ceil((double)wei / (double)K);
if(N >= n) ans++;
wei += n;
N -= n;
}
cout << ans << endl;
}
| CPP |
p00389 Pilling Blocks | We make a tower by stacking up blocks. The tower consists of several stages and each stage is constructed by connecting blocks horizontally. Each block is of the same weight and is tough enough to withstand the weight equivalent to up to $K$ blocks without crushing.
We have to build the tower abiding by the following conditions:
* Every stage of the tower has one or more blocks on it.
* Each block is loaded with weight that falls within the withstanding range of the block. The weight loaded on a block in a stage is evaluated by: total weight of all blocks above the stage divided by the number of blocks within the stage.
Given the number of blocks and the strength, make a program to evaluate the maximum height (i.e., stages) of the tower than can be constructed.
Input
The input is given in the following format.
$N$ $K$
The input line provides the number of blocks available $N$ ($1 \leq N \leq 10^5$) and the strength of the block $K$ ($1 \leq K \leq 10^5$).
Output
Output the maximum possible number of stages.
Examples
Input
4 2
Output
3
Input
5 2
Output
4 | 7 | 0 | #include <bits/stdc++.h>
using namespace std;
using llong = long long;
using ldbl = long double;
using P = pair<llong, llong>;
#define BE(x) x.begin(), x.end()
const llong inf = llong(1e18)+7;
const llong mod = 1e9+7;
int main(){
llong N, K;
cin >> N >> K;
llong now = 1, ans = 1;
N--;
while(true){
llong next = now/K + (now%K>0);
if(N < next)
break;
now += next;
N -= next;
ans++;
}
cout << ans << endl;
return 0;
}
| CPP |
p00389 Pilling Blocks | We make a tower by stacking up blocks. The tower consists of several stages and each stage is constructed by connecting blocks horizontally. Each block is of the same weight and is tough enough to withstand the weight equivalent to up to $K$ blocks without crushing.
We have to build the tower abiding by the following conditions:
* Every stage of the tower has one or more blocks on it.
* Each block is loaded with weight that falls within the withstanding range of the block. The weight loaded on a block in a stage is evaluated by: total weight of all blocks above the stage divided by the number of blocks within the stage.
Given the number of blocks and the strength, make a program to evaluate the maximum height (i.e., stages) of the tower than can be constructed.
Input
The input is given in the following format.
$N$ $K$
The input line provides the number of blocks available $N$ ($1 \leq N \leq 10^5$) and the strength of the block $K$ ($1 \leq K \leq 10^5$).
Output
Output the maximum possible number of stages.
Examples
Input
4 2
Output
3
Input
5 2
Output
4 | 7 | 0 | #include<iostream>
#include<cassert>
using namespace std;
int solve(int N, int K){
int t = 1;
int n = 1;
int a = 1;
while(1){
n = (K+a-1)/K;
a += n;
if ( N < a ) return t;
t++;
}
}
int main() {
int N, K; cin >> N >> K;
int t = solve(N, K);
cout << t << endl;
}
| CPP |
p00389 Pilling Blocks | We make a tower by stacking up blocks. The tower consists of several stages and each stage is constructed by connecting blocks horizontally. Each block is of the same weight and is tough enough to withstand the weight equivalent to up to $K$ blocks without crushing.
We have to build the tower abiding by the following conditions:
* Every stage of the tower has one or more blocks on it.
* Each block is loaded with weight that falls within the withstanding range of the block. The weight loaded on a block in a stage is evaluated by: total weight of all blocks above the stage divided by the number of blocks within the stage.
Given the number of blocks and the strength, make a program to evaluate the maximum height (i.e., stages) of the tower than can be constructed.
Input
The input is given in the following format.
$N$ $K$
The input line provides the number of blocks available $N$ ($1 \leq N \leq 10^5$) and the strength of the block $K$ ($1 \leq K \leq 10^5$).
Output
Output the maximum possible number of stages.
Examples
Input
4 2
Output
3
Input
5 2
Output
4 | 7 | 0 | #include <bits/stdc++.h>
#include <assert.h>
using namespace std;
int main()
{
int n, k;
cin >> n >> k;
n--;
int sum = 1, ans = 1;
while ((sum + k - 1) / k <= n)
{
n -= (sum + k - 1) / k;
sum += (sum + k - 1) / k;
ans++;
}
cout << ans << endl;
return 0;
}
| CPP |
p00389 Pilling Blocks | We make a tower by stacking up blocks. The tower consists of several stages and each stage is constructed by connecting blocks horizontally. Each block is of the same weight and is tough enough to withstand the weight equivalent to up to $K$ blocks without crushing.
We have to build the tower abiding by the following conditions:
* Every stage of the tower has one or more blocks on it.
* Each block is loaded with weight that falls within the withstanding range of the block. The weight loaded on a block in a stage is evaluated by: total weight of all blocks above the stage divided by the number of blocks within the stage.
Given the number of blocks and the strength, make a program to evaluate the maximum height (i.e., stages) of the tower than can be constructed.
Input
The input is given in the following format.
$N$ $K$
The input line provides the number of blocks available $N$ ($1 \leq N \leq 10^5$) and the strength of the block $K$ ($1 \leq K \leq 10^5$).
Output
Output the maximum possible number of stages.
Examples
Input
4 2
Output
3
Input
5 2
Output
4 | 7 | 0 | #include<bits/stdc++.h>
typedef long long int ll;
typedef unsigned long long int ull;
#define BIG_NUM 2000000000
#define HUGE_NUM 99999999999999999
#define MOD 1000000007
#define EPS 0.000000001
using namespace std;
int main(){
int N,K;
scanf("%d %d",&N,&K);
int ans = 1,upper = 1;
int rest = N-1,need;
while(true){
if(upper%K == 0){
need = upper/K;
}else{
need = (upper/K)+1;
}
if(need > rest){
break;
}
rest -= need;
upper += need;
ans++;
}
printf("%d\n",ans);
return 0;
}
| CPP |
p00389 Pilling Blocks | We make a tower by stacking up blocks. The tower consists of several stages and each stage is constructed by connecting blocks horizontally. Each block is of the same weight and is tough enough to withstand the weight equivalent to up to $K$ blocks without crushing.
We have to build the tower abiding by the following conditions:
* Every stage of the tower has one or more blocks on it.
* Each block is loaded with weight that falls within the withstanding range of the block. The weight loaded on a block in a stage is evaluated by: total weight of all blocks above the stage divided by the number of blocks within the stage.
Given the number of blocks and the strength, make a program to evaluate the maximum height (i.e., stages) of the tower than can be constructed.
Input
The input is given in the following format.
$N$ $K$
The input line provides the number of blocks available $N$ ($1 \leq N \leq 10^5$) and the strength of the block $K$ ($1 \leq K \leq 10^5$).
Output
Output the maximum possible number of stages.
Examples
Input
4 2
Output
3
Input
5 2
Output
4 | 7 | 0 | #include <bits/stdc++.h>
using namespace std;
int main() {
int n, k; cin >> n >> k;
int remove = 0, count = 0;
if( n <= k + 1 ) {
cout << n << endl;
} else {
n -= k + 1;
remove += k + 1;
while( 1 ) {
n -= ceil( static_cast<double>( remove ) / k );
remove += ceil( static_cast<double>( remove ) / k );
if( n < 0 ) {
break;
}
count++;
}
cout << count + k + 1 << endl;
}
}
| CPP |
p00389 Pilling Blocks | We make a tower by stacking up blocks. The tower consists of several stages and each stage is constructed by connecting blocks horizontally. Each block is of the same weight and is tough enough to withstand the weight equivalent to up to $K$ blocks without crushing.
We have to build the tower abiding by the following conditions:
* Every stage of the tower has one or more blocks on it.
* Each block is loaded with weight that falls within the withstanding range of the block. The weight loaded on a block in a stage is evaluated by: total weight of all blocks above the stage divided by the number of blocks within the stage.
Given the number of blocks and the strength, make a program to evaluate the maximum height (i.e., stages) of the tower than can be constructed.
Input
The input is given in the following format.
$N$ $K$
The input line provides the number of blocks available $N$ ($1 \leq N \leq 10^5$) and the strength of the block $K$ ($1 \leq K \leq 10^5$).
Output
Output the maximum possible number of stages.
Examples
Input
4 2
Output
3
Input
5 2
Output
4 | 7 | 0 | #include <cstdio>
#include <vector>
#include <algorithm>
#include <utility>
bool valid(int N, int K, int x) {
int wsum = 1;
for (int i = 1; i < x; ++i) {
int n = (wsum+K-1) / K;
wsum += n;
if (wsum > N) return false;
}
return wsum <= N;
}
int main() {
int N, K;
scanf("%d %d", &N, &K);
int lb = 1;
int ub = N+1;
while (ub-lb > 1) {
int mid = (lb+ub) >> 1;
(valid(N, K, mid)? lb:ub) = mid;
}
printf("%d\n", lb);
}
| CPP |
p00389 Pilling Blocks | We make a tower by stacking up blocks. The tower consists of several stages and each stage is constructed by connecting blocks horizontally. Each block is of the same weight and is tough enough to withstand the weight equivalent to up to $K$ blocks without crushing.
We have to build the tower abiding by the following conditions:
* Every stage of the tower has one or more blocks on it.
* Each block is loaded with weight that falls within the withstanding range of the block. The weight loaded on a block in a stage is evaluated by: total weight of all blocks above the stage divided by the number of blocks within the stage.
Given the number of blocks and the strength, make a program to evaluate the maximum height (i.e., stages) of the tower than can be constructed.
Input
The input is given in the following format.
$N$ $K$
The input line provides the number of blocks available $N$ ($1 \leq N \leq 10^5$) and the strength of the block $K$ ($1 \leq K \leq 10^5$).
Output
Output the maximum possible number of stages.
Examples
Input
4 2
Output
3
Input
5 2
Output
4 | 7 | 0 | #include<iostream>
using namespace std;
int main(){
int n, k; cin >> n >> k;
k++;
int ans = 0;
while (n > 0) {
int m = (n + k - 1) / k;
n -= m;
ans++;
}
cout << ans << endl;
return 0;
}
| CPP |
p00389 Pilling Blocks | We make a tower by stacking up blocks. The tower consists of several stages and each stage is constructed by connecting blocks horizontally. Each block is of the same weight and is tough enough to withstand the weight equivalent to up to $K$ blocks without crushing.
We have to build the tower abiding by the following conditions:
* Every stage of the tower has one or more blocks on it.
* Each block is loaded with weight that falls within the withstanding range of the block. The weight loaded on a block in a stage is evaluated by: total weight of all blocks above the stage divided by the number of blocks within the stage.
Given the number of blocks and the strength, make a program to evaluate the maximum height (i.e., stages) of the tower than can be constructed.
Input
The input is given in the following format.
$N$ $K$
The input line provides the number of blocks available $N$ ($1 \leq N \leq 10^5$) and the strength of the block $K$ ($1 \leq K \leq 10^5$).
Output
Output the maximum possible number of stages.
Examples
Input
4 2
Output
3
Input
5 2
Output
4 | 7 | 0 | import java.util.Scanner;
public class Main {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
long base = sc.nextLong(), K = sc.nextLong();
long next;
int ans = 1;
while (base >= 1) {
long low = 0, high = base;
while (high - low > 1) {
long willNext = (low + high) / 2;
if(willNext <= K*(base - willNext)) {//OK
low = willNext;
} else {
high = willNext;
}
}
next = low;
if (next > 0) {
base = next;
ans++;
} else {
break;
}
}
System.out.println(ans);
}
}
| JAVA |
p00389 Pilling Blocks | We make a tower by stacking up blocks. The tower consists of several stages and each stage is constructed by connecting blocks horizontally. Each block is of the same weight and is tough enough to withstand the weight equivalent to up to $K$ blocks without crushing.
We have to build the tower abiding by the following conditions:
* Every stage of the tower has one or more blocks on it.
* Each block is loaded with weight that falls within the withstanding range of the block. The weight loaded on a block in a stage is evaluated by: total weight of all blocks above the stage divided by the number of blocks within the stage.
Given the number of blocks and the strength, make a program to evaluate the maximum height (i.e., stages) of the tower than can be constructed.
Input
The input is given in the following format.
$N$ $K$
The input line provides the number of blocks available $N$ ($1 \leq N \leq 10^5$) and the strength of the block $K$ ($1 \leq K \leq 10^5$).
Output
Output the maximum possible number of stages.
Examples
Input
4 2
Output
3
Input
5 2
Output
4 | 7 | 0 | #include<bits/stdc++.h>
using namespace std;
int main(){
int n,k,x=0,sum=0,a=1;
cin>>n>>k;
while(1){
if(sum>=n) break;
sum+=a;
if((sum-a)/a>=k){
sum-=a; ++a; --x;
}
++x;
}
cout<<x<<endl;
return 0;
}
| CPP |
p00389 Pilling Blocks | We make a tower by stacking up blocks. The tower consists of several stages and each stage is constructed by connecting blocks horizontally. Each block is of the same weight and is tough enough to withstand the weight equivalent to up to $K$ blocks without crushing.
We have to build the tower abiding by the following conditions:
* Every stage of the tower has one or more blocks on it.
* Each block is loaded with weight that falls within the withstanding range of the block. The weight loaded on a block in a stage is evaluated by: total weight of all blocks above the stage divided by the number of blocks within the stage.
Given the number of blocks and the strength, make a program to evaluate the maximum height (i.e., stages) of the tower than can be constructed.
Input
The input is given in the following format.
$N$ $K$
The input line provides the number of blocks available $N$ ($1 \leq N \leq 10^5$) and the strength of the block $K$ ($1 \leq K \leq 10^5$).
Output
Output the maximum possible number of stages.
Examples
Input
4 2
Output
3
Input
5 2
Output
4 | 7 | 0 | #include <bits/stdc++.h>
using namespace std;
using ll = long long;
using VI = vector<int>;
using VL = vector<ll>;
#define FOR(i,a,n) for(int (i)=(a);(i)<(n);(i)++)
#define eFOR(i,a,n) for(int (i)=(a);(i)<=(n);(i)++)
#define rFOR(i,a,n) for(int (i)=(n)-1;(i)>=(a);(i)--)
#define erFOR(i,a,n) for(int (i)=(n);(i)>=(a);(i)--)
#define SORT(i) sort((i).begin(),(i).end())
#define rSORT(i,a) sort((i).begin(),(i).end(),(a))
#define all(i) (i).begin(),(i).end()
constexpr ll INF = 1000000000;
constexpr ll LLINF = 1LL << 60;
constexpr ll mod = 1000000007;
constexpr ll MOD = 998244353;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; }return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; }return 0; }
inline void init() { cin.tie(nullptr); cout.tie(nullptr); cin.tie(nullptr); ios::sync_with_stdio(false); cout << fixed << setprecision(15); }
template<class T> inline istream& operator>>(istream& input, vector<T>& v) { for (auto& elemnt : v)input >> elemnt; return input; }
int main() {
init();
int n, k;
cin >> n >> k;
n--;
int sum = 1, ans = 1;
while (1) {
int num = sum / k + (bool)(sum % k);
if (n < num)break;
ans++;
sum += num;
n -= num;
}
cout << ans << "\n";
}
| CPP |
p00389 Pilling Blocks | We make a tower by stacking up blocks. The tower consists of several stages and each stage is constructed by connecting blocks horizontally. Each block is of the same weight and is tough enough to withstand the weight equivalent to up to $K$ blocks without crushing.
We have to build the tower abiding by the following conditions:
* Every stage of the tower has one or more blocks on it.
* Each block is loaded with weight that falls within the withstanding range of the block. The weight loaded on a block in a stage is evaluated by: total weight of all blocks above the stage divided by the number of blocks within the stage.
Given the number of blocks and the strength, make a program to evaluate the maximum height (i.e., stages) of the tower than can be constructed.
Input
The input is given in the following format.
$N$ $K$
The input line provides the number of blocks available $N$ ($1 \leq N \leq 10^5$) and the strength of the block $K$ ($1 \leq K \leq 10^5$).
Output
Output the maximum possible number of stages.
Examples
Input
4 2
Output
3
Input
5 2
Output
4 | 7 | 0 | // 2018/12/09 Tazoe
#include <iostream>
using namespace std;
int main()
{
int N, K;
cin >> N >> K;
int cnt = 0;
while(N>0){
int x = (N-1)/(K+1)+1;
N -= x;
cnt++;
}
cout << cnt << endl;
return 0;
}
| CPP |
p00389 Pilling Blocks | We make a tower by stacking up blocks. The tower consists of several stages and each stage is constructed by connecting blocks horizontally. Each block is of the same weight and is tough enough to withstand the weight equivalent to up to $K$ blocks without crushing.
We have to build the tower abiding by the following conditions:
* Every stage of the tower has one or more blocks on it.
* Each block is loaded with weight that falls within the withstanding range of the block. The weight loaded on a block in a stage is evaluated by: total weight of all blocks above the stage divided by the number of blocks within the stage.
Given the number of blocks and the strength, make a program to evaluate the maximum height (i.e., stages) of the tower than can be constructed.
Input
The input is given in the following format.
$N$ $K$
The input line provides the number of blocks available $N$ ($1 \leq N \leq 10^5$) and the strength of the block $K$ ($1 \leq K \leq 10^5$).
Output
Output the maximum possible number of stages.
Examples
Input
4 2
Output
3
Input
5 2
Output
4 | 7 | 0 | #include <bits/stdc++.h>
using namespace std;
int main(){
int n, k;
cin >> n >> k;
int ans = 1, t = 1;
while((t += (t+k-1)/k) <= n) ans++;
cout << ans << endl;
return 0;
}
| CPP |
p00389 Pilling Blocks | We make a tower by stacking up blocks. The tower consists of several stages and each stage is constructed by connecting blocks horizontally. Each block is of the same weight and is tough enough to withstand the weight equivalent to up to $K$ blocks without crushing.
We have to build the tower abiding by the following conditions:
* Every stage of the tower has one or more blocks on it.
* Each block is loaded with weight that falls within the withstanding range of the block. The weight loaded on a block in a stage is evaluated by: total weight of all blocks above the stage divided by the number of blocks within the stage.
Given the number of blocks and the strength, make a program to evaluate the maximum height (i.e., stages) of the tower than can be constructed.
Input
The input is given in the following format.
$N$ $K$
The input line provides the number of blocks available $N$ ($1 \leq N \leq 10^5$) and the strength of the block $K$ ($1 \leq K \leq 10^5$).
Output
Output the maximum possible number of stages.
Examples
Input
4 2
Output
3
Input
5 2
Output
4 | 7 | 0 | #include <iostream>
#include <iomanip>
#include <cstdio>
#include <string>
#include <cstring>
#include <deque>
#include <list>
#include <queue>
#include <stack>
#include <vector>
#include <utility>
#include <algorithm>
#include <map>
#include <set>
#include <complex>
#include <cmath>
#include <limits>
#include <cfloat>
#include <climits>
#include <ctime>
#include <cassert>
#include <numeric>
#include <fstream>
#include <functional>
#include <bitset>
using namespace std;
#define int long long int
const int INF = 1000000007;
signed main(){
int n, k; cin >> n >> k;
double sum = 0;
int hight = 0;
while(1){
// sum に耐えうる個数のうち, 最小のものを求める
int l = 0;
int r = 100010;
while(r - l > 1){
int d = (r + l) / 2;
double w = INF;
if(d != 0) w = sum / d;
if(w <= k) r = d;
else l = d;
}
if(r <= n){
hight++;
n -= r;
sum += r;
}else{
cout << hight << endl;
return 0;
}
}
return 0;
}
| CPP |
p00389 Pilling Blocks | We make a tower by stacking up blocks. The tower consists of several stages and each stage is constructed by connecting blocks horizontally. Each block is of the same weight and is tough enough to withstand the weight equivalent to up to $K$ blocks without crushing.
We have to build the tower abiding by the following conditions:
* Every stage of the tower has one or more blocks on it.
* Each block is loaded with weight that falls within the withstanding range of the block. The weight loaded on a block in a stage is evaluated by: total weight of all blocks above the stage divided by the number of blocks within the stage.
Given the number of blocks and the strength, make a program to evaluate the maximum height (i.e., stages) of the tower than can be constructed.
Input
The input is given in the following format.
$N$ $K$
The input line provides the number of blocks available $N$ ($1 \leq N \leq 10^5$) and the strength of the block $K$ ($1 \leq K \leq 10^5$).
Output
Output the maximum possible number of stages.
Examples
Input
4 2
Output
3
Input
5 2
Output
4 | 7 | 0 | #include <iostream>
using namespace std;
int main() {
int n, k;
cin >> n >> k;
int ret = 1;
int used = 1;
while (true) {
used += (used + k - 1) / k;
if (used > n)break;
ret++;
}
cout << ret << endl;
return 0;
}
| CPP |
p00389 Pilling Blocks | We make a tower by stacking up blocks. The tower consists of several stages and each stage is constructed by connecting blocks horizontally. Each block is of the same weight and is tough enough to withstand the weight equivalent to up to $K$ blocks without crushing.
We have to build the tower abiding by the following conditions:
* Every stage of the tower has one or more blocks on it.
* Each block is loaded with weight that falls within the withstanding range of the block. The weight loaded on a block in a stage is evaluated by: total weight of all blocks above the stage divided by the number of blocks within the stage.
Given the number of blocks and the strength, make a program to evaluate the maximum height (i.e., stages) of the tower than can be constructed.
Input
The input is given in the following format.
$N$ $K$
The input line provides the number of blocks available $N$ ($1 \leq N \leq 10^5$) and the strength of the block $K$ ($1 \leq K \leq 10^5$).
Output
Output the maximum possible number of stages.
Examples
Input
4 2
Output
3
Input
5 2
Output
4 | 7 | 0 | #include <iostream>
#include <iomanip>
#include <cstdio>
#include <string>
#include <cstring>
#include <deque>
#include <list>
#include <queue>
#include <stack>
#include <vector>
#include <utility>
#include <algorithm>
#include <map>
#include <set>
#include <complex>
#include <cmath>
#include <limits>
#include <cfloat>
#include <climits>
#include <ctime>
#include <cassert>
#include <numeric>
#include <fstream>
#include <functional>
#include <bitset>
#define chmin(a, b) ((a) = min((a), (b)))
#define chmax(a, b) ((a) = max((a), (b)))
#define fs first
#define sc second
#define eb emplace_back
using namespace std;
typedef long long ll;
typedef pair<int, int> P;
typedef tuple<int, int, int> T;
const ll MOD = 1e9 + 7;
const ll INF = 1e18;
const double pi = acos(-1);
const double eps = 1e-10;
int dx[] = {1, 0, -1, 0};
int dy[] = {0, -1, 0, 1};
int main(){
int n, k; cin>>n>>k;
int ans = 0;
int sum = 0;
for(int i=0; i<n; i++){
int cur = 1;
bool valid = false;
while(i < n){
if((sum + (cur - 1)) / cur <= k){
valid = true;
break;
}
cur++;
i++;
}
sum += cur;
if(valid){
ans++;
}
}
cout << ans << endl;
}
| CPP |
p00389 Pilling Blocks | We make a tower by stacking up blocks. The tower consists of several stages and each stage is constructed by connecting blocks horizontally. Each block is of the same weight and is tough enough to withstand the weight equivalent to up to $K$ blocks without crushing.
We have to build the tower abiding by the following conditions:
* Every stage of the tower has one or more blocks on it.
* Each block is loaded with weight that falls within the withstanding range of the block. The weight loaded on a block in a stage is evaluated by: total weight of all blocks above the stage divided by the number of blocks within the stage.
Given the number of blocks and the strength, make a program to evaluate the maximum height (i.e., stages) of the tower than can be constructed.
Input
The input is given in the following format.
$N$ $K$
The input line provides the number of blocks available $N$ ($1 \leq N \leq 10^5$) and the strength of the block $K$ ($1 \leq K \leq 10^5$).
Output
Output the maximum possible number of stages.
Examples
Input
4 2
Output
3
Input
5 2
Output
4 | 7 | 0 | N, K = map(int, input().split())
ans = 1
s = 1
N -= 1
while 1:
m = (s+K-1) // K
if N < m:
break
s += m; N -= m
ans += 1
print(ans)
| PYTHON3 |
p00389 Pilling Blocks | We make a tower by stacking up blocks. The tower consists of several stages and each stage is constructed by connecting blocks horizontally. Each block is of the same weight and is tough enough to withstand the weight equivalent to up to $K$ blocks without crushing.
We have to build the tower abiding by the following conditions:
* Every stage of the tower has one or more blocks on it.
* Each block is loaded with weight that falls within the withstanding range of the block. The weight loaded on a block in a stage is evaluated by: total weight of all blocks above the stage divided by the number of blocks within the stage.
Given the number of blocks and the strength, make a program to evaluate the maximum height (i.e., stages) of the tower than can be constructed.
Input
The input is given in the following format.
$N$ $K$
The input line provides the number of blocks available $N$ ($1 \leq N \leq 10^5$) and the strength of the block $K$ ($1 \leq K \leq 10^5$).
Output
Output the maximum possible number of stages.
Examples
Input
4 2
Output
3
Input
5 2
Output
4 | 7 | 0 | N, K = (int(x) for x in input().split())
t = 1
r = N - 1
s = 1
while True:
b = s // K + 1 if s % K else s // K
if r >= b:
r -= b
s += b
t += 1
else:
break
print(t)
| PYTHON3 |
p00389 Pilling Blocks | We make a tower by stacking up blocks. The tower consists of several stages and each stage is constructed by connecting blocks horizontally. Each block is of the same weight and is tough enough to withstand the weight equivalent to up to $K$ blocks without crushing.
We have to build the tower abiding by the following conditions:
* Every stage of the tower has one or more blocks on it.
* Each block is loaded with weight that falls within the withstanding range of the block. The weight loaded on a block in a stage is evaluated by: total weight of all blocks above the stage divided by the number of blocks within the stage.
Given the number of blocks and the strength, make a program to evaluate the maximum height (i.e., stages) of the tower than can be constructed.
Input
The input is given in the following format.
$N$ $K$
The input line provides the number of blocks available $N$ ($1 \leq N \leq 10^5$) and the strength of the block $K$ ($1 \leq K \leq 10^5$).
Output
Output the maximum possible number of stages.
Examples
Input
4 2
Output
3
Input
5 2
Output
4 | 7 | 0 | #include <bits/stdc++.h>
using namespace std;
int main()
{
int N, K;
int cnt = 0;
int num = 0;
cin >> N >> K;
for ( int i = 0; i < N; i++ ) {
num++;
if ( num * K >= N - i - 1 ) {
num = 0;
cnt++;
}
}
cout << cnt << endl;
return ( 0 );
}
| CPP |
p00389 Pilling Blocks | We make a tower by stacking up blocks. The tower consists of several stages and each stage is constructed by connecting blocks horizontally. Each block is of the same weight and is tough enough to withstand the weight equivalent to up to $K$ blocks without crushing.
We have to build the tower abiding by the following conditions:
* Every stage of the tower has one or more blocks on it.
* Each block is loaded with weight that falls within the withstanding range of the block. The weight loaded on a block in a stage is evaluated by: total weight of all blocks above the stage divided by the number of blocks within the stage.
Given the number of blocks and the strength, make a program to evaluate the maximum height (i.e., stages) of the tower than can be constructed.
Input
The input is given in the following format.
$N$ $K$
The input line provides the number of blocks available $N$ ($1 \leq N \leq 10^5$) and the strength of the block $K$ ($1 \leq K \leq 10^5$).
Output
Output the maximum possible number of stages.
Examples
Input
4 2
Output
3
Input
5 2
Output
4 | 7 | 0 |
N,K = [int(i) for i in input().split()]
weight = 1
ans = 1
N -= 1
while N > 0:
d = 0
if weight % K == 0:
d = weight // K
else:
d = weight // K + 1
N -= d
weight += d
if N >= 0:
ans += 1
print(ans)
| PYTHON3 |
p00389 Pilling Blocks | We make a tower by stacking up blocks. The tower consists of several stages and each stage is constructed by connecting blocks horizontally. Each block is of the same weight and is tough enough to withstand the weight equivalent to up to $K$ blocks without crushing.
We have to build the tower abiding by the following conditions:
* Every stage of the tower has one or more blocks on it.
* Each block is loaded with weight that falls within the withstanding range of the block. The weight loaded on a block in a stage is evaluated by: total weight of all blocks above the stage divided by the number of blocks within the stage.
Given the number of blocks and the strength, make a program to evaluate the maximum height (i.e., stages) of the tower than can be constructed.
Input
The input is given in the following format.
$N$ $K$
The input line provides the number of blocks available $N$ ($1 \leq N \leq 10^5$) and the strength of the block $K$ ($1 \leq K \leq 10^5$).
Output
Output the maximum possible number of stages.
Examples
Input
4 2
Output
3
Input
5 2
Output
4 | 7 | 0 | #include<iostream>
#include<algorithm>
#include<vector>
#include<string>
#define int long long
using namespace std;
signed main() {
int n, k; cin >> n >> k;
int sum = 0, ans = 0;
while (sum < n) {
int p = (sum + k - 1) / k;
if (!sum)p = 1;
if (sum + p > n)break;
sum += p;
ans++;
}
cout << ans << endl;
}
| CPP |
p00389 Pilling Blocks | We make a tower by stacking up blocks. The tower consists of several stages and each stage is constructed by connecting blocks horizontally. Each block is of the same weight and is tough enough to withstand the weight equivalent to up to $K$ blocks without crushing.
We have to build the tower abiding by the following conditions:
* Every stage of the tower has one or more blocks on it.
* Each block is loaded with weight that falls within the withstanding range of the block. The weight loaded on a block in a stage is evaluated by: total weight of all blocks above the stage divided by the number of blocks within the stage.
Given the number of blocks and the strength, make a program to evaluate the maximum height (i.e., stages) of the tower than can be constructed.
Input
The input is given in the following format.
$N$ $K$
The input line provides the number of blocks available $N$ ($1 \leq N \leq 10^5$) and the strength of the block $K$ ($1 \leq K \leq 10^5$).
Output
Output the maximum possible number of stages.
Examples
Input
4 2
Output
3
Input
5 2
Output
4 | 7 | 0 | #define _USE_MATH_DEFINES
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <iostream>
#include <cmath>
#include <algorithm>
#include <vector>
#include <queue>
#include <map>
using namespace std;
typedef pair<long long int, long long int> P;
long long int INF = 1e18;
long long int MOD = 1e9 + 7;
int main(){
int N, K;
cin >> N >> K;
int ans = 0;
int S = 0;
int cur = 0;
for(int i = 0; i < N; i++){
cur += 1;
if(S <= cur * K){
ans += 1;
S += cur;
cur = 0;
}
}
cout << ans << endl;
return 0;
}
| CPP |
p00389 Pilling Blocks | We make a tower by stacking up blocks. The tower consists of several stages and each stage is constructed by connecting blocks horizontally. Each block is of the same weight and is tough enough to withstand the weight equivalent to up to $K$ blocks without crushing.
We have to build the tower abiding by the following conditions:
* Every stage of the tower has one or more blocks on it.
* Each block is loaded with weight that falls within the withstanding range of the block. The weight loaded on a block in a stage is evaluated by: total weight of all blocks above the stage divided by the number of blocks within the stage.
Given the number of blocks and the strength, make a program to evaluate the maximum height (i.e., stages) of the tower than can be constructed.
Input
The input is given in the following format.
$N$ $K$
The input line provides the number of blocks available $N$ ($1 \leq N \leq 10^5$) and the strength of the block $K$ ($1 \leq K \leq 10^5$).
Output
Output the maximum possible number of stages.
Examples
Input
4 2
Output
3
Input
5 2
Output
4 | 7 | 0 | //yukicoder@cpp14
//author:luckYrat(twitter:@luckYrat_)
//<ここに一言>
//せんげん!
#include <iostream>
#include <cmath>
#include <algorithm>
#include <iomanip>
#include <string>
#include <vector>
#include <set>
#include <stack>
#include <queue>
#include <map>
#include <bitset>
#include <cctype>
#include <utility>
#include <climits>
//なまえくーかん!
using namespace std;
using ll = long long;
using P = pair<ll,ll>;
//てーすう!
const int mod = 1000000007;
const int inf = (1<<30)-1;
const ll linf = (1LL<<62LL)-1;
const double EPS = (1e-10);
//でふぁいん!
#define anyfill(n,s) setw(n) << setfill(s)
#define loop(s) for(int i = 0; s > i; i++)
#define rep(i,q) for(int i = 0; (q) > i; i++)
#define repp(i,n,q) for(int i = n; (q) > i; i++)
#define dep(i,q) for(int i = (q); 0 < i; i--)
//みじかく!
#define pb push_back
#define fir first
#define scn second
#define ednl endl
//いぇすのー!
#define YesNo(a) (a?"Yes":"No")
#define YESNO(a) (a?"YES":"NO")
#define yesno(a) (a?"yes":"no")
//きんぼーnほーこー!!
P ar4[4] = {{0,1},{0,-1},{1,0},{-1,0}};
P ar8[8] = {{-1,-1},{-1,0},{-1,1},{0,-1},{0,1},{1,-1},{1,0},{1,1}};
/*
確認ポイント
cout << fixed << setprecision(n) << 小数計算//n桁の小数表記になる
計算量は変わらないが楽できるシリーズ
min(max)_element(iter,iter)で一番小さい(大きい)値のポインタが帰ってくる
count(iter,iter,int)でintがiterからiterの間にいくつあったかを取得できる
*/
template <typename T>
T gcd(T a,T b){
if(a%b==0)return b;
else return gcd(b,a%b);
}
template <typename T>
T lcm(T a,T b){
return a/gcd(a,b)*b;
}
int dp[200][200];
struct z{
int a,b,c;
};
__attribute__((constructor))
void initial() {
cin.tie(0);
ios::sync_with_stdio(false);
}
int main(){
int n,k;cin>>n>>k;
int nw = 1;
int z = 1;
int ans = 1;
while(n >= nw){
while(nw > k*z){
z++;
}
nw+=z;
ans++;
}
cout << ans-1 << endl;
}
| CPP |
p00389 Pilling Blocks | We make a tower by stacking up blocks. The tower consists of several stages and each stage is constructed by connecting blocks horizontally. Each block is of the same weight and is tough enough to withstand the weight equivalent to up to $K$ blocks without crushing.
We have to build the tower abiding by the following conditions:
* Every stage of the tower has one or more blocks on it.
* Each block is loaded with weight that falls within the withstanding range of the block. The weight loaded on a block in a stage is evaluated by: total weight of all blocks above the stage divided by the number of blocks within the stage.
Given the number of blocks and the strength, make a program to evaluate the maximum height (i.e., stages) of the tower than can be constructed.
Input
The input is given in the following format.
$N$ $K$
The input line provides the number of blocks available $N$ ($1 \leq N \leq 10^5$) and the strength of the block $K$ ($1 \leq K \leq 10^5$).
Output
Output the maximum possible number of stages.
Examples
Input
4 2
Output
3
Input
5 2
Output
4 | 7 | 0 | #include<iostream>
#include<algorithm>
#include<vector>
using namespace std;
typedef long long ll;
#define mod 1000000007
int main(){
ll n,k; cin>>n>>k;
ll ans=0,sum=0;
while(1){
ll need=(sum+k-1)/k;
if(need==0)need=1;
if(n<need)break;
n-=need;
sum+=need;
ans++;
}
cout<<ans<<endl;
return 0;
}
| CPP |
p00389 Pilling Blocks | We make a tower by stacking up blocks. The tower consists of several stages and each stage is constructed by connecting blocks horizontally. Each block is of the same weight and is tough enough to withstand the weight equivalent to up to $K$ blocks without crushing.
We have to build the tower abiding by the following conditions:
* Every stage of the tower has one or more blocks on it.
* Each block is loaded with weight that falls within the withstanding range of the block. The weight loaded on a block in a stage is evaluated by: total weight of all blocks above the stage divided by the number of blocks within the stage.
Given the number of blocks and the strength, make a program to evaluate the maximum height (i.e., stages) of the tower than can be constructed.
Input
The input is given in the following format.
$N$ $K$
The input line provides the number of blocks available $N$ ($1 \leq N \leq 10^5$) and the strength of the block $K$ ($1 \leq K \leq 10^5$).
Output
Output the maximum possible number of stages.
Examples
Input
4 2
Output
3
Input
5 2
Output
4 | 7 | 0 | #include<cstdio>
#include<functional>
#include<algorithm>
using namespace std;
int main(void)
{
int n,k,x,sum,cnt;
scanf("%d %d",&n,&k);
cnt=1; sum=1; n--;
while(1) {
x=sum/k+(sum%k!=0);
if(x>n) break;
cnt++; n-=x; sum+=x;
}
printf("%d\n",cnt);
return 0;
}
| CPP |
p00389 Pilling Blocks | We make a tower by stacking up blocks. The tower consists of several stages and each stage is constructed by connecting blocks horizontally. Each block is of the same weight and is tough enough to withstand the weight equivalent to up to $K$ blocks without crushing.
We have to build the tower abiding by the following conditions:
* Every stage of the tower has one or more blocks on it.
* Each block is loaded with weight that falls within the withstanding range of the block. The weight loaded on a block in a stage is evaluated by: total weight of all blocks above the stage divided by the number of blocks within the stage.
Given the number of blocks and the strength, make a program to evaluate the maximum height (i.e., stages) of the tower than can be constructed.
Input
The input is given in the following format.
$N$ $K$
The input line provides the number of blocks available $N$ ($1 \leq N \leq 10^5$) and the strength of the block $K$ ($1 \leq K \leq 10^5$).
Output
Output the maximum possible number of stages.
Examples
Input
4 2
Output
3
Input
5 2
Output
4 | 7 | 0 | n,k = map(int,input().split())
ans = 0
d,s = 1,0
while True:
# s/d <= k
# s <= d*k
while d*k < s:
d += 1
if s+d > n:
break
s += d
ans += 1
print(ans)
| PYTHON3 |
p00389 Pilling Blocks | We make a tower by stacking up blocks. The tower consists of several stages and each stage is constructed by connecting blocks horizontally. Each block is of the same weight and is tough enough to withstand the weight equivalent to up to $K$ blocks without crushing.
We have to build the tower abiding by the following conditions:
* Every stage of the tower has one or more blocks on it.
* Each block is loaded with weight that falls within the withstanding range of the block. The weight loaded on a block in a stage is evaluated by: total weight of all blocks above the stage divided by the number of blocks within the stage.
Given the number of blocks and the strength, make a program to evaluate the maximum height (i.e., stages) of the tower than can be constructed.
Input
The input is given in the following format.
$N$ $K$
The input line provides the number of blocks available $N$ ($1 \leq N \leq 10^5$) and the strength of the block $K$ ($1 \leq K \leq 10^5$).
Output
Output the maximum possible number of stages.
Examples
Input
4 2
Output
3
Input
5 2
Output
4 | 7 | 0 | #include <iostream>
using namespace std;
int main()
{
int n, k, m = 0, i = 1, j = 0;
cin >> n >> k;
while (1) {
while (j > k * i)
i++;
if (n - j < i)
break;
m++;
j += i;
}
cout << m << endl;
return 0;
}
| CPP |
p00389 Pilling Blocks | We make a tower by stacking up blocks. The tower consists of several stages and each stage is constructed by connecting blocks horizontally. Each block is of the same weight and is tough enough to withstand the weight equivalent to up to $K$ blocks without crushing.
We have to build the tower abiding by the following conditions:
* Every stage of the tower has one or more blocks on it.
* Each block is loaded with weight that falls within the withstanding range of the block. The weight loaded on a block in a stage is evaluated by: total weight of all blocks above the stage divided by the number of blocks within the stage.
Given the number of blocks and the strength, make a program to evaluate the maximum height (i.e., stages) of the tower than can be constructed.
Input
The input is given in the following format.
$N$ $K$
The input line provides the number of blocks available $N$ ($1 \leq N \leq 10^5$) and the strength of the block $K$ ($1 \leq K \leq 10^5$).
Output
Output the maximum possible number of stages.
Examples
Input
4 2
Output
3
Input
5 2
Output
4 | 7 | 0 | #include<iostream>
#include<vector>
#include<set>
#include<algorithm>
#include<queue>
#include<utility>
#define LL long long
using namespace std;
int main() {
int n, _n, k;
cin >> n >> k;
int sum = 1, ans = 1;
_n = n - 1;
while ((sum + k - 1) / k <= _n) {
_n -= (sum + k - 1) / k;
sum += (sum + k - 1) / k;
ans++;
}
cout << ans << endl;
return 0;
}
| CPP |
p00389 Pilling Blocks | We make a tower by stacking up blocks. The tower consists of several stages and each stage is constructed by connecting blocks horizontally. Each block is of the same weight and is tough enough to withstand the weight equivalent to up to $K$ blocks without crushing.
We have to build the tower abiding by the following conditions:
* Every stage of the tower has one or more blocks on it.
* Each block is loaded with weight that falls within the withstanding range of the block. The weight loaded on a block in a stage is evaluated by: total weight of all blocks above the stage divided by the number of blocks within the stage.
Given the number of blocks and the strength, make a program to evaluate the maximum height (i.e., stages) of the tower than can be constructed.
Input
The input is given in the following format.
$N$ $K$
The input line provides the number of blocks available $N$ ($1 \leq N \leq 10^5$) and the strength of the block $K$ ($1 \leq K \leq 10^5$).
Output
Output the maximum possible number of stages.
Examples
Input
4 2
Output
3
Input
5 2
Output
4 | 7 | 0 | #include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int,int> P;
int main() {
cin.tie(0);
ios::sync_with_stdio(false);
ll N,K; cin >> N >> K;
ll ans = 1;
ll sum = 1;
N--;
while(true){
if(N*K < sum) break;
ll tmp = 0;
if(sum%K == 0) tmp = sum/K;
else tmp = (sum/K)+1;
sum += tmp;
ans++;
N -= tmp;
}
cout << ans << endl;
return 0;
}
| CPP |
p00389 Pilling Blocks | We make a tower by stacking up blocks. The tower consists of several stages and each stage is constructed by connecting blocks horizontally. Each block is of the same weight and is tough enough to withstand the weight equivalent to up to $K$ blocks without crushing.
We have to build the tower abiding by the following conditions:
* Every stage of the tower has one or more blocks on it.
* Each block is loaded with weight that falls within the withstanding range of the block. The weight loaded on a block in a stage is evaluated by: total weight of all blocks above the stage divided by the number of blocks within the stage.
Given the number of blocks and the strength, make a program to evaluate the maximum height (i.e., stages) of the tower than can be constructed.
Input
The input is given in the following format.
$N$ $K$
The input line provides the number of blocks available $N$ ($1 \leq N \leq 10^5$) and the strength of the block $K$ ($1 \leq K \leq 10^5$).
Output
Output the maximum possible number of stages.
Examples
Input
4 2
Output
3
Input
5 2
Output
4 | 7 | 0 | #include <bits/stdc++.h>
using namespace std;
int main() {
int n, k, m=1, sum=0, ans=0;
cin >> n >> k;
while(n>=m){
ans++;
sum += m;
n -= m;
m = (sum-1)/k+1;
}
cout << ans << endl;
return 0;
}
| CPP |
p00389 Pilling Blocks | We make a tower by stacking up blocks. The tower consists of several stages and each stage is constructed by connecting blocks horizontally. Each block is of the same weight and is tough enough to withstand the weight equivalent to up to $K$ blocks without crushing.
We have to build the tower abiding by the following conditions:
* Every stage of the tower has one or more blocks on it.
* Each block is loaded with weight that falls within the withstanding range of the block. The weight loaded on a block in a stage is evaluated by: total weight of all blocks above the stage divided by the number of blocks within the stage.
Given the number of blocks and the strength, make a program to evaluate the maximum height (i.e., stages) of the tower than can be constructed.
Input
The input is given in the following format.
$N$ $K$
The input line provides the number of blocks available $N$ ($1 \leq N \leq 10^5$) and the strength of the block $K$ ($1 \leq K \leq 10^5$).
Output
Output the maximum possible number of stages.
Examples
Input
4 2
Output
3
Input
5 2
Output
4 | 7 | 0 | n, k = map(int, input().split())
weight = 1
rest = n - 1
layers = 1
while True:
add = weight // k + bool(weight % k)
if add <= rest:
rest -= add
weight += add
layers += 1
else:
break
print(layers)
| PYTHON3 |
p00389 Pilling Blocks | We make a tower by stacking up blocks. The tower consists of several stages and each stage is constructed by connecting blocks horizontally. Each block is of the same weight and is tough enough to withstand the weight equivalent to up to $K$ blocks without crushing.
We have to build the tower abiding by the following conditions:
* Every stage of the tower has one or more blocks on it.
* Each block is loaded with weight that falls within the withstanding range of the block. The weight loaded on a block in a stage is evaluated by: total weight of all blocks above the stage divided by the number of blocks within the stage.
Given the number of blocks and the strength, make a program to evaluate the maximum height (i.e., stages) of the tower than can be constructed.
Input
The input is given in the following format.
$N$ $K$
The input line provides the number of blocks available $N$ ($1 \leq N \leq 10^5$) and the strength of the block $K$ ($1 \leq K \leq 10^5$).
Output
Output the maximum possible number of stages.
Examples
Input
4 2
Output
3
Input
5 2
Output
4 | 7 | 0 | #include <cstdio>
#include <cstdlib>
#include <cmath>
#include <cstring>
#include <iostream>
#include <complex>
#include <string>
#include <algorithm>
#include <numeric>
#include <vector>
#include <queue>
#include <stack>
#include <map>
#include <set>
#include <unordered_map>
#include <unordered_set>
#include <functional>
#include <cassert>
typedef long long ll;
using namespace std;
#define debug(x) cerr << __LINE__ << " : " << #x << " = " << (x) << endl;
#define mod 1000000007 //1e9+7(prime number)
#define INF 1000000000 //1e9
#define LLINF 2000000000000000000LL //2e18
#define SIZE 100010
int main(){
int N, K;
int ans = 0, use = 0;
cin >> N >> K;
for(int i=0;i<N;i++){
int p = max(1, (use + K - 1)/K);
if(use + p > N) break;
use += p;
ans++;
}
cout << ans << endl;
return 0;
}
| CPP |
p00389 Pilling Blocks | We make a tower by stacking up blocks. The tower consists of several stages and each stage is constructed by connecting blocks horizontally. Each block is of the same weight and is tough enough to withstand the weight equivalent to up to $K$ blocks without crushing.
We have to build the tower abiding by the following conditions:
* Every stage of the tower has one or more blocks on it.
* Each block is loaded with weight that falls within the withstanding range of the block. The weight loaded on a block in a stage is evaluated by: total weight of all blocks above the stage divided by the number of blocks within the stage.
Given the number of blocks and the strength, make a program to evaluate the maximum height (i.e., stages) of the tower than can be constructed.
Input
The input is given in the following format.
$N$ $K$
The input line provides the number of blocks available $N$ ($1 \leq N \leq 10^5$) and the strength of the block $K$ ($1 \leq K \leq 10^5$).
Output
Output the maximum possible number of stages.
Examples
Input
4 2
Output
3
Input
5 2
Output
4 | 7 | 0 | #include <iostream>
#include <vector>
using std::vector;
using std::cin;
using std::cout;
using std::endl;
int main()
{
int N, K, num = 0; // N: ブロック個数、K: ブロック強度、num: 積み上げるブロック数
vector<int> digit;
cin >> N >> K;
for (;;) {
int n = 0;
while (num > ++n * K);
num += n;
if (num > N) {
break;
}
digit.push_back(n);
}
cout << digit.size() << endl;
return 0;
}
| CPP |
p00389 Pilling Blocks | We make a tower by stacking up blocks. The tower consists of several stages and each stage is constructed by connecting blocks horizontally. Each block is of the same weight and is tough enough to withstand the weight equivalent to up to $K$ blocks without crushing.
We have to build the tower abiding by the following conditions:
* Every stage of the tower has one or more blocks on it.
* Each block is loaded with weight that falls within the withstanding range of the block. The weight loaded on a block in a stage is evaluated by: total weight of all blocks above the stage divided by the number of blocks within the stage.
Given the number of blocks and the strength, make a program to evaluate the maximum height (i.e., stages) of the tower than can be constructed.
Input
The input is given in the following format.
$N$ $K$
The input line provides the number of blocks available $N$ ($1 \leq N \leq 10^5$) and the strength of the block $K$ ($1 \leq K \leq 10^5$).
Output
Output the maximum possible number of stages.
Examples
Input
4 2
Output
3
Input
5 2
Output
4 | 7 | 0 | #include<bits/stdc++.h>
#define V vector
#define VI vector<int>
#define VVI vector<vector<int>>
#define rep(i,n) for(int i=0;i<(n);i++)
#define MOD 1000000007
using namespace std;
int main(void){
int N,K;
cin>>N>>K;
int t=1,n=1,a=1;
while(1){
n=(K+a-1)/K;
a+=n;
if(N<a){
cout<<t<<endl;
return 0;
}
t++;
}
}
| CPP |
p00389 Pilling Blocks | We make a tower by stacking up blocks. The tower consists of several stages and each stage is constructed by connecting blocks horizontally. Each block is of the same weight and is tough enough to withstand the weight equivalent to up to $K$ blocks without crushing.
We have to build the tower abiding by the following conditions:
* Every stage of the tower has one or more blocks on it.
* Each block is loaded with weight that falls within the withstanding range of the block. The weight loaded on a block in a stage is evaluated by: total weight of all blocks above the stage divided by the number of blocks within the stage.
Given the number of blocks and the strength, make a program to evaluate the maximum height (i.e., stages) of the tower than can be constructed.
Input
The input is given in the following format.
$N$ $K$
The input line provides the number of blocks available $N$ ($1 \leq N \leq 10^5$) and the strength of the block $K$ ($1 \leq K \leq 10^5$).
Output
Output the maximum possible number of stages.
Examples
Input
4 2
Output
3
Input
5 2
Output
4 | 7 | 0 | #include <iostream>
using namespace std;
int main() {
int n, k;
cin >> n >> k;
n--;
int result = 1;
int used = 1;
int use;
while (n >= 0) {
result++;
use = (used + k - 1) / k;
used += use;
n -= use;
}
cout << result - 1 << endl;
return 0;
}
| CPP |
p00389 Pilling Blocks | We make a tower by stacking up blocks. The tower consists of several stages and each stage is constructed by connecting blocks horizontally. Each block is of the same weight and is tough enough to withstand the weight equivalent to up to $K$ blocks without crushing.
We have to build the tower abiding by the following conditions:
* Every stage of the tower has one or more blocks on it.
* Each block is loaded with weight that falls within the withstanding range of the block. The weight loaded on a block in a stage is evaluated by: total weight of all blocks above the stage divided by the number of blocks within the stage.
Given the number of blocks and the strength, make a program to evaluate the maximum height (i.e., stages) of the tower than can be constructed.
Input
The input is given in the following format.
$N$ $K$
The input line provides the number of blocks available $N$ ($1 \leq N \leq 10^5$) and the strength of the block $K$ ($1 \leq K \leq 10^5$).
Output
Output the maximum possible number of stages.
Examples
Input
4 2
Output
3
Input
5 2
Output
4 | 7 | 0 | #include <iostream>
using namespace std;
long long N, K;
int main() {
cin >> N >> K;
long long ret = 1, cnt = 1;
while (true) {
long long nex = (ret + K - 1) / K;
if (ret + nex > N) {
cout << cnt << endl;
return 0;
}
ret += nex;
cnt++;
}
return 0;
}
| CPP |
p00389 Pilling Blocks | We make a tower by stacking up blocks. The tower consists of several stages and each stage is constructed by connecting blocks horizontally. Each block is of the same weight and is tough enough to withstand the weight equivalent to up to $K$ blocks without crushing.
We have to build the tower abiding by the following conditions:
* Every stage of the tower has one or more blocks on it.
* Each block is loaded with weight that falls within the withstanding range of the block. The weight loaded on a block in a stage is evaluated by: total weight of all blocks above the stage divided by the number of blocks within the stage.
Given the number of blocks and the strength, make a program to evaluate the maximum height (i.e., stages) of the tower than can be constructed.
Input
The input is given in the following format.
$N$ $K$
The input line provides the number of blocks available $N$ ($1 \leq N \leq 10^5$) and the strength of the block $K$ ($1 \leq K \leq 10^5$).
Output
Output the maximum possible number of stages.
Examples
Input
4 2
Output
3
Input
5 2
Output
4 | 7 | 0 | #include "bits/stdc++.h"
#pragma warning(disable:4996)
using namespace std;
int main() {
int N,K;cin>>N>>K;
int ans=0;
int sum=0;
while (true) {
int next=(sum-1)/K+1;
if(ans==0)next=1;
if (N < sum + next) {
break;
}
else {
sum+=next;
ans++;
}
}
cout<<ans<<endl;
return 0;
}
| CPP |
p00605 Vampirish Night | There is a vampire family of N members. Vampires are also known as extreme gourmets. Of course vampires' foods are human blood. However, not all kinds of blood is acceptable for them. Vampires drink blood that K blood types of ones are mixed, and each vampire has his/her favorite amount for each blood type.
You, cook of the family, are looking inside a fridge to prepare dinner. Your first task is to write a program that judges if all family members' dinner can be prepared using blood in the fridge.
Constraints
* Judge data includes at most 100 data sets.
* 1 ≤ N ≤ 100
* 1 ≤ K ≤ 100
* 0 ≤ Si ≤ 100000
* 0 ≤ Bij ≤ 1000
Input
Input file consists of a number of data sets. One data set is given in following format:
N K
S1 S2 ... SK
B11 B12 ... B1K
B21 B22 ... B2K
:
BN1 BN2 ... BNK
N and K indicate the number of family members and the number of blood types respectively.
Si is an integer that indicates the amount of blood of the i-th blood type that is in a fridge.
Bij is an integer that indicates the amount of blood of the j-th blood type that the i-th vampire uses.
The end of input is indicated by a case where N = K = 0. You should print nothing for this data set.
Output
For each set, print "Yes" if everyone's dinner can be prepared using blood in a fridge, "No" otherwise (without quotes).
Example
Input
2 3
5 4 5
1 2 3
3 2 1
3 5
1 2 3 4 5
0 1 0 1 2
0 1 1 2 2
1 0 3 1 1
0 0
Output
Yes
No | 7 | 0 | #include <iostream>
#include <vector>
using namespace std;
int main(){
int n,k,t;
bool f=true;
vector<int> s;
while(1){
cin >> n >> k;
if(n==0&&k==0) break;
for(int i=0;i<k;i++){
cin >> t;
s.push_back(t);
}
for(int i=0;i<n;i++){
for(int j=0;j<k;j++){
cin >> t;
s[j]-=t;
}
}
for(int i=0;i<k;i++){
if(s[i]<0){ f=false; }
}
if(f){
cout << "Yes" << endl;
} else {
cout << "No" << endl;
}
s.erase(s.begin(),s.end());
f=true;
}
} | CPP |
p00605 Vampirish Night | There is a vampire family of N members. Vampires are also known as extreme gourmets. Of course vampires' foods are human blood. However, not all kinds of blood is acceptable for them. Vampires drink blood that K blood types of ones are mixed, and each vampire has his/her favorite amount for each blood type.
You, cook of the family, are looking inside a fridge to prepare dinner. Your first task is to write a program that judges if all family members' dinner can be prepared using blood in the fridge.
Constraints
* Judge data includes at most 100 data sets.
* 1 ≤ N ≤ 100
* 1 ≤ K ≤ 100
* 0 ≤ Si ≤ 100000
* 0 ≤ Bij ≤ 1000
Input
Input file consists of a number of data sets. One data set is given in following format:
N K
S1 S2 ... SK
B11 B12 ... B1K
B21 B22 ... B2K
:
BN1 BN2 ... BNK
N and K indicate the number of family members and the number of blood types respectively.
Si is an integer that indicates the amount of blood of the i-th blood type that is in a fridge.
Bij is an integer that indicates the amount of blood of the j-th blood type that the i-th vampire uses.
The end of input is indicated by a case where N = K = 0. You should print nothing for this data set.
Output
For each set, print "Yes" if everyone's dinner can be prepared using blood in a fridge, "No" otherwise (without quotes).
Example
Input
2 3
5 4 5
1 2 3
3 2 1
3 5
1 2 3 4 5
0 1 0 1 2
0 1 1 2 2
1 0 3 1 1
0 0
Output
Yes
No | 7 | 0 | #include <iostream>
#include <vector>
#include <string>
#include <cstring>
#include <algorithm>
#include <sstream>
#include <map>
#include <set>
#define REP(i,k,n) for(int i=k;i<n;i++)
#define rep(i,n) for(int i=0;i<n;i++)
#define INF 1<<30
#define pb push_back
#define mp make_pair
using namespace std;
typedef long long ll;
typedef pair<int,int> P;
int main() {
int n,k;
while(cin >> n >> k) {
if(n == 0 && k == 0) break;
vector<int> v(k);
rep(i,k) cin >> v[i];
bool flag = true;
rep(i,n) {
rep(j,k) {
int x;
cin >> x;
v[j] -= x;
if(v[j] < 0) {
flag = false;
}
}
}
if(flag) cout << "Yes" << endl;
else cout << "No" << endl;
}
return 0;
} | CPP |
p00605 Vampirish Night | There is a vampire family of N members. Vampires are also known as extreme gourmets. Of course vampires' foods are human blood. However, not all kinds of blood is acceptable for them. Vampires drink blood that K blood types of ones are mixed, and each vampire has his/her favorite amount for each blood type.
You, cook of the family, are looking inside a fridge to prepare dinner. Your first task is to write a program that judges if all family members' dinner can be prepared using blood in the fridge.
Constraints
* Judge data includes at most 100 data sets.
* 1 ≤ N ≤ 100
* 1 ≤ K ≤ 100
* 0 ≤ Si ≤ 100000
* 0 ≤ Bij ≤ 1000
Input
Input file consists of a number of data sets. One data set is given in following format:
N K
S1 S2 ... SK
B11 B12 ... B1K
B21 B22 ... B2K
:
BN1 BN2 ... BNK
N and K indicate the number of family members and the number of blood types respectively.
Si is an integer that indicates the amount of blood of the i-th blood type that is in a fridge.
Bij is an integer that indicates the amount of blood of the j-th blood type that the i-th vampire uses.
The end of input is indicated by a case where N = K = 0. You should print nothing for this data set.
Output
For each set, print "Yes" if everyone's dinner can be prepared using blood in a fridge, "No" otherwise (without quotes).
Example
Input
2 3
5 4 5
1 2 3
3 2 1
3 5
1 2 3 4 5
0 1 0 1 2
0 1 1 2 2
1 0 3 1 1
0 0
Output
Yes
No | 7 | 0 | import java.io.*;
public class Main{
public static void main(String[] args)throws IOException{
BufferedReader r=new BufferedReader(new InputStreamReader(System.in));
while(true){
String s=r.readLine();
String[] t=s.split(" ");
int[] n=new int[t.length];
for(int i=0;i<2;i++){
n[i]=Integer.parseInt(t[i]);
}
if(n[0]==0 &&n[1]==0){
System.exit(0);
}
String u=r.readLine();
String[] p=u.split(" ");
int[] ing=new int[n[1]];
for(int j=0;j<n[1];j++){
ing[j]=Integer.parseInt(p[j]);
}
int[] count=new int[n[1]];
for(int nm=0;nm<n[1];nm++){
count[nm]=0;
}
for(int k=0;k<n[0];k++){
String a=r.readLine();
String[] alpha;
alpha=a.split(" ");
int[] number=new int[n[1]];
for(int l=0;l<n[1];l++){
number[l]=Integer.parseInt(alpha[l]);
count[l]+=number[l];
}
}
int ans=0;
for(int q=0;q<n[1];q++){
if(count[q]<=ing[q]){
ans++;
}
}
if(ans==n[1]){
System.out.println("Yes");
}else{
System.out.println("No");
}
}
}
} | JAVA |
p00605 Vampirish Night | There is a vampire family of N members. Vampires are also known as extreme gourmets. Of course vampires' foods are human blood. However, not all kinds of blood is acceptable for them. Vampires drink blood that K blood types of ones are mixed, and each vampire has his/her favorite amount for each blood type.
You, cook of the family, are looking inside a fridge to prepare dinner. Your first task is to write a program that judges if all family members' dinner can be prepared using blood in the fridge.
Constraints
* Judge data includes at most 100 data sets.
* 1 ≤ N ≤ 100
* 1 ≤ K ≤ 100
* 0 ≤ Si ≤ 100000
* 0 ≤ Bij ≤ 1000
Input
Input file consists of a number of data sets. One data set is given in following format:
N K
S1 S2 ... SK
B11 B12 ... B1K
B21 B22 ... B2K
:
BN1 BN2 ... BNK
N and K indicate the number of family members and the number of blood types respectively.
Si is an integer that indicates the amount of blood of the i-th blood type that is in a fridge.
Bij is an integer that indicates the amount of blood of the j-th blood type that the i-th vampire uses.
The end of input is indicated by a case where N = K = 0. You should print nothing for this data set.
Output
For each set, print "Yes" if everyone's dinner can be prepared using blood in a fridge, "No" otherwise (without quotes).
Example
Input
2 3
5 4 5
1 2 3
3 2 1
3 5
1 2 3 4 5
0 1 0 1 2
0 1 1 2 2
1 0 3 1 1
0 0
Output
Yes
No | 7 | 0 | #include<stdio.h>
int s[100];
int main(){
int n,k;
int i,j;
while(1){
scanf("%d %d",&n,&k);
if(n==0)return 0;
for(i=0;i<k;i++)scanf("%d",&s[i]);
for(i=0;i<n;i++){
for(j=0;j<k;j++){
int x;
scanf("%d",&x);
s[j]-=x;
}
}
for(i=0;i<k;i++)if(s[i]<0)break;
if(i==k)printf("Yes\n");
else printf("No\n");
}
} | CPP |
p00605 Vampirish Night | There is a vampire family of N members. Vampires are also known as extreme gourmets. Of course vampires' foods are human blood. However, not all kinds of blood is acceptable for them. Vampires drink blood that K blood types of ones are mixed, and each vampire has his/her favorite amount for each blood type.
You, cook of the family, are looking inside a fridge to prepare dinner. Your first task is to write a program that judges if all family members' dinner can be prepared using blood in the fridge.
Constraints
* Judge data includes at most 100 data sets.
* 1 ≤ N ≤ 100
* 1 ≤ K ≤ 100
* 0 ≤ Si ≤ 100000
* 0 ≤ Bij ≤ 1000
Input
Input file consists of a number of data sets. One data set is given in following format:
N K
S1 S2 ... SK
B11 B12 ... B1K
B21 B22 ... B2K
:
BN1 BN2 ... BNK
N and K indicate the number of family members and the number of blood types respectively.
Si is an integer that indicates the amount of blood of the i-th blood type that is in a fridge.
Bij is an integer that indicates the amount of blood of the j-th blood type that the i-th vampire uses.
The end of input is indicated by a case where N = K = 0. You should print nothing for this data set.
Output
For each set, print "Yes" if everyone's dinner can be prepared using blood in a fridge, "No" otherwise (without quotes).
Example
Input
2 3
5 4 5
1 2 3
3 2 1
3 5
1 2 3 4 5
0 1 0 1 2
0 1 1 2 2
1 0 3 1 1
0 0
Output
Yes
No | 7 | 0 | #include<iostream>
#include<sstream>
#include<vector>
#include<set>
#include<map>
#include<queue>
#include<algorithm>
#include<numeric>
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<cmath>
#include<cassert>
#define rep(i,n) for(int i=0;i<n;i++)
#define all(c) (c).begin(),(c).end()
#define mp make_pair
#define pb push_back
#define rp(i,c) rep(i,(c).size())
#define fr(i,c) for(__typeof((c).begin()) i=(c).begin();i!=(c).end();i++)
#define dbg(x) cerr<<#x<<" = "<<(x)<<endl
using namespace std;
typedef long long ll;
typedef vector<int> vi;
typedef pair<int,int> pi;
const int inf=1<<28;
const double INF=1e12,EPS=1e-9;
int main()
{
int n,k;
while(cin>>n>>k,n)
{
int b[k],t;
rep(i,k)cin>>b[i];
rep(i,n)rep(j,k)cin>>t,b[j]-=t;
rep(i,k)if(b[i]<0)
{
cout<<"No"<<endl; goto END;
}
cout<<"Yes"<<endl; END:;
}
return 0;
} | CPP |
p00605 Vampirish Night | There is a vampire family of N members. Vampires are also known as extreme gourmets. Of course vampires' foods are human blood. However, not all kinds of blood is acceptable for them. Vampires drink blood that K blood types of ones are mixed, and each vampire has his/her favorite amount for each blood type.
You, cook of the family, are looking inside a fridge to prepare dinner. Your first task is to write a program that judges if all family members' dinner can be prepared using blood in the fridge.
Constraints
* Judge data includes at most 100 data sets.
* 1 ≤ N ≤ 100
* 1 ≤ K ≤ 100
* 0 ≤ Si ≤ 100000
* 0 ≤ Bij ≤ 1000
Input
Input file consists of a number of data sets. One data set is given in following format:
N K
S1 S2 ... SK
B11 B12 ... B1K
B21 B22 ... B2K
:
BN1 BN2 ... BNK
N and K indicate the number of family members and the number of blood types respectively.
Si is an integer that indicates the amount of blood of the i-th blood type that is in a fridge.
Bij is an integer that indicates the amount of blood of the j-th blood type that the i-th vampire uses.
The end of input is indicated by a case where N = K = 0. You should print nothing for this data set.
Output
For each set, print "Yes" if everyone's dinner can be prepared using blood in a fridge, "No" otherwise (without quotes).
Example
Input
2 3
5 4 5
1 2 3
3 2 1
3 5
1 2 3 4 5
0 1 0 1 2
0 1 1 2 2
1 0 3 1 1
0 0
Output
Yes
No | 7 | 0 | import java.util.Scanner;
public class Main {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
int n, k;
int s[];
int a[][];
boolean f;
while (true) {
n = sc.nextInt();
k = sc.nextInt();
if ((n | k) == 0) {
break;
}
s = new int[k];
for (int i = 0; i < k; i++) {
s[i] = sc.nextInt();
}
f = true;
for (int i = 0; i < n; i++) {
for (int j = 0; j < k; j++) {
s[j] -= sc.nextInt();
if (s[j] < 0) {
f = false;
}
}
}
System.out.println(f == true ? "Yes" : "No");
}
}
} | JAVA |
p00605 Vampirish Night | There is a vampire family of N members. Vampires are also known as extreme gourmets. Of course vampires' foods are human blood. However, not all kinds of blood is acceptable for them. Vampires drink blood that K blood types of ones are mixed, and each vampire has his/her favorite amount for each blood type.
You, cook of the family, are looking inside a fridge to prepare dinner. Your first task is to write a program that judges if all family members' dinner can be prepared using blood in the fridge.
Constraints
* Judge data includes at most 100 data sets.
* 1 ≤ N ≤ 100
* 1 ≤ K ≤ 100
* 0 ≤ Si ≤ 100000
* 0 ≤ Bij ≤ 1000
Input
Input file consists of a number of data sets. One data set is given in following format:
N K
S1 S2 ... SK
B11 B12 ... B1K
B21 B22 ... B2K
:
BN1 BN2 ... BNK
N and K indicate the number of family members and the number of blood types respectively.
Si is an integer that indicates the amount of blood of the i-th blood type that is in a fridge.
Bij is an integer that indicates the amount of blood of the j-th blood type that the i-th vampire uses.
The end of input is indicated by a case where N = K = 0. You should print nothing for this data set.
Output
For each set, print "Yes" if everyone's dinner can be prepared using blood in a fridge, "No" otherwise (without quotes).
Example
Input
2 3
5 4 5
1 2 3
3 2 1
3 5
1 2 3 4 5
0 1 0 1 2
0 1 1 2 2
1 0 3 1 1
0 0
Output
Yes
No | 7 | 0 | #include<iostream>
#include<string>
using namespace std;
int main(){
while(true){
int N,K;
string ans = "Yes";
cin >> N >> K;
int S[K];
if( N == 0 && K == 0 ) break;
for(int i = 0; i < K; ++i){
cin >> S[i];
}
for(int i = 0; i < N; ++i){
for(int j = 0; j < K; ++j){
int B; cin >> B; S[j] -= B;
}
}
for(int i = 0; i < K; ++i){
if( S[i] < 0 ){
ans = "No";
}
}
cout << ans << endl;
}
return 0;
} | CPP |
p00605 Vampirish Night | There is a vampire family of N members. Vampires are also known as extreme gourmets. Of course vampires' foods are human blood. However, not all kinds of blood is acceptable for them. Vampires drink blood that K blood types of ones are mixed, and each vampire has his/her favorite amount for each blood type.
You, cook of the family, are looking inside a fridge to prepare dinner. Your first task is to write a program that judges if all family members' dinner can be prepared using blood in the fridge.
Constraints
* Judge data includes at most 100 data sets.
* 1 ≤ N ≤ 100
* 1 ≤ K ≤ 100
* 0 ≤ Si ≤ 100000
* 0 ≤ Bij ≤ 1000
Input
Input file consists of a number of data sets. One data set is given in following format:
N K
S1 S2 ... SK
B11 B12 ... B1K
B21 B22 ... B2K
:
BN1 BN2 ... BNK
N and K indicate the number of family members and the number of blood types respectively.
Si is an integer that indicates the amount of blood of the i-th blood type that is in a fridge.
Bij is an integer that indicates the amount of blood of the j-th blood type that the i-th vampire uses.
The end of input is indicated by a case where N = K = 0. You should print nothing for this data set.
Output
For each set, print "Yes" if everyone's dinner can be prepared using blood in a fridge, "No" otherwise (without quotes).
Example
Input
2 3
5 4 5
1 2 3
3 2 1
3 5
1 2 3 4 5
0 1 0 1 2
0 1 1 2 2
1 0 3 1 1
0 0
Output
Yes
No | 7 | 0 | #include <iostream>
using namespace std;
int main() {
int n, k;
while (cin >> n >> k) {
if (n == 0 && k == 0) {
break;
}
int s[100];
bool hantei = true;
for (int i = 0; i < k; i++) {
cin >> s[i];
}
int a;
for (int i = 0; i < n; i++) {
for (int j = 0; j < k; j++) {
cin >> a;
s[j] -= a;
if (s[j] < 0) {
hantei = false;
}
}
}
if (hantei) {
cout << "Yes" << endl;
} else {
cout << "No" << endl;
}
}
return 0;
} | CPP |
p00605 Vampirish Night | There is a vampire family of N members. Vampires are also known as extreme gourmets. Of course vampires' foods are human blood. However, not all kinds of blood is acceptable for them. Vampires drink blood that K blood types of ones are mixed, and each vampire has his/her favorite amount for each blood type.
You, cook of the family, are looking inside a fridge to prepare dinner. Your first task is to write a program that judges if all family members' dinner can be prepared using blood in the fridge.
Constraints
* Judge data includes at most 100 data sets.
* 1 ≤ N ≤ 100
* 1 ≤ K ≤ 100
* 0 ≤ Si ≤ 100000
* 0 ≤ Bij ≤ 1000
Input
Input file consists of a number of data sets. One data set is given in following format:
N K
S1 S2 ... SK
B11 B12 ... B1K
B21 B22 ... B2K
:
BN1 BN2 ... BNK
N and K indicate the number of family members and the number of blood types respectively.
Si is an integer that indicates the amount of blood of the i-th blood type that is in a fridge.
Bij is an integer that indicates the amount of blood of the j-th blood type that the i-th vampire uses.
The end of input is indicated by a case where N = K = 0. You should print nothing for this data set.
Output
For each set, print "Yes" if everyone's dinner can be prepared using blood in a fridge, "No" otherwise (without quotes).
Example
Input
2 3
5 4 5
1 2 3
3 2 1
3 5
1 2 3 4 5
0 1 0 1 2
0 1 1 2 2
1 0 3 1 1
0 0
Output
Yes
No | 7 | 0 | #include<iostream>
using namespace std;
int main(){int n,k,l,i;while(1){cin>>n>>k;if(n==0&&k==0)break;int s[k];for(i=0;i<k;i++)s[i]=0,cin>>s[i];for(i=0;i<n;i++)for(int j=0;j<k;j++)cin>>l,s[j]-=l;for(i=0;i<k;i++){if(s[i]<0){cout<<"No\n";break;}if(i==k-1)cout<<"Yes\n";}}} | CPP |
p00605 Vampirish Night | There is a vampire family of N members. Vampires are also known as extreme gourmets. Of course vampires' foods are human blood. However, not all kinds of blood is acceptable for them. Vampires drink blood that K blood types of ones are mixed, and each vampire has his/her favorite amount for each blood type.
You, cook of the family, are looking inside a fridge to prepare dinner. Your first task is to write a program that judges if all family members' dinner can be prepared using blood in the fridge.
Constraints
* Judge data includes at most 100 data sets.
* 1 ≤ N ≤ 100
* 1 ≤ K ≤ 100
* 0 ≤ Si ≤ 100000
* 0 ≤ Bij ≤ 1000
Input
Input file consists of a number of data sets. One data set is given in following format:
N K
S1 S2 ... SK
B11 B12 ... B1K
B21 B22 ... B2K
:
BN1 BN2 ... BNK
N and K indicate the number of family members and the number of blood types respectively.
Si is an integer that indicates the amount of blood of the i-th blood type that is in a fridge.
Bij is an integer that indicates the amount of blood of the j-th blood type that the i-th vampire uses.
The end of input is indicated by a case where N = K = 0. You should print nothing for this data set.
Output
For each set, print "Yes" if everyone's dinner can be prepared using blood in a fridge, "No" otherwise (without quotes).
Example
Input
2 3
5 4 5
1 2 3
3 2 1
3 5
1 2 3 4 5
0 1 0 1 2
0 1 1 2 2
1 0 3 1 1
0 0
Output
Yes
No | 7 | 0 | #include<bits/stdc++.h>
using namespace std;
int N, K;
int M[110];
int main()
{
while(cin >> N >> K && N && K)
{
bool flag = false;
for(int i = 0; i < K; i++)cin >> M[i];
for(int i = 0; i < N; i++)
{
for(int j = 0; j < K; j++)
{
int m;
cin >> m;
M[j] -= m;
if(M[j] < 0)flag = true;
}
}
if(flag)printf("No\n");
else printf("Yes\n");
}
return 0;
}
| CPP |
p00605 Vampirish Night | There is a vampire family of N members. Vampires are also known as extreme gourmets. Of course vampires' foods are human blood. However, not all kinds of blood is acceptable for them. Vampires drink blood that K blood types of ones are mixed, and each vampire has his/her favorite amount for each blood type.
You, cook of the family, are looking inside a fridge to prepare dinner. Your first task is to write a program that judges if all family members' dinner can be prepared using blood in the fridge.
Constraints
* Judge data includes at most 100 data sets.
* 1 ≤ N ≤ 100
* 1 ≤ K ≤ 100
* 0 ≤ Si ≤ 100000
* 0 ≤ Bij ≤ 1000
Input
Input file consists of a number of data sets. One data set is given in following format:
N K
S1 S2 ... SK
B11 B12 ... B1K
B21 B22 ... B2K
:
BN1 BN2 ... BNK
N and K indicate the number of family members and the number of blood types respectively.
Si is an integer that indicates the amount of blood of the i-th blood type that is in a fridge.
Bij is an integer that indicates the amount of blood of the j-th blood type that the i-th vampire uses.
The end of input is indicated by a case where N = K = 0. You should print nothing for this data set.
Output
For each set, print "Yes" if everyone's dinner can be prepared using blood in a fridge, "No" otherwise (without quotes).
Example
Input
2 3
5 4 5
1 2 3
3 2 1
3 5
1 2 3 4 5
0 1 0 1 2
0 1 1 2 2
1 0 3 1 1
0 0
Output
Yes
No | 7 | 0 | #define _CRT_SECURE_NO_WARNINGS
#include <bits/stdc++.h>
using namespace std;
using ll=long long;
const int MAX = (int)1e2;
int N, K;
void solve() {
int s[MAX ];
bool ok=0;
int b;
//int b[MAX ][MAX];
for (int i = 0; i < K; i++) {
cin >> s[i];
}
for (int i = 0; i < N; i++) {
for (int j = 0; j < K; j++) {
cin >> b;
s[j] -= b;
}
}
ok = 1;
for (int i = 0; i < K; i++) {
if (s[i] < 0) {
ok = 0;
break;
}
}
cout << ((ok) ? "Yes" : "No") << endl;
}
int main() {
while (1) {
cin >> N >> K;
if (N == 0 && K == 0) {
break;
}
solve();
}
} | CPP |
p00605 Vampirish Night | There is a vampire family of N members. Vampires are also known as extreme gourmets. Of course vampires' foods are human blood. However, not all kinds of blood is acceptable for them. Vampires drink blood that K blood types of ones are mixed, and each vampire has his/her favorite amount for each blood type.
You, cook of the family, are looking inside a fridge to prepare dinner. Your first task is to write a program that judges if all family members' dinner can be prepared using blood in the fridge.
Constraints
* Judge data includes at most 100 data sets.
* 1 ≤ N ≤ 100
* 1 ≤ K ≤ 100
* 0 ≤ Si ≤ 100000
* 0 ≤ Bij ≤ 1000
Input
Input file consists of a number of data sets. One data set is given in following format:
N K
S1 S2 ... SK
B11 B12 ... B1K
B21 B22 ... B2K
:
BN1 BN2 ... BNK
N and K indicate the number of family members and the number of blood types respectively.
Si is an integer that indicates the amount of blood of the i-th blood type that is in a fridge.
Bij is an integer that indicates the amount of blood of the j-th blood type that the i-th vampire uses.
The end of input is indicated by a case where N = K = 0. You should print nothing for this data set.
Output
For each set, print "Yes" if everyone's dinner can be prepared using blood in a fridge, "No" otherwise (without quotes).
Example
Input
2 3
5 4 5
1 2 3
3 2 1
3 5
1 2 3 4 5
0 1 0 1 2
0 1 1 2 2
1 0 3 1 1
0 0
Output
Yes
No | 7 | 0 | while True:
N,K=map(int,raw_input().split())
if N==K==0:break
S=map(int,raw_input().split())
L=[0]*K
for i in range(N):
temp=map(int,raw_input().split())
for j in range(K):
L[j]+=temp[j]
for i in range(K):
if S[i]-L[i]<0:
print "No"
break
else:
print "Yes" | PYTHON |
p00605 Vampirish Night | There is a vampire family of N members. Vampires are also known as extreme gourmets. Of course vampires' foods are human blood. However, not all kinds of blood is acceptable for them. Vampires drink blood that K blood types of ones are mixed, and each vampire has his/her favorite amount for each blood type.
You, cook of the family, are looking inside a fridge to prepare dinner. Your first task is to write a program that judges if all family members' dinner can be prepared using blood in the fridge.
Constraints
* Judge data includes at most 100 data sets.
* 1 ≤ N ≤ 100
* 1 ≤ K ≤ 100
* 0 ≤ Si ≤ 100000
* 0 ≤ Bij ≤ 1000
Input
Input file consists of a number of data sets. One data set is given in following format:
N K
S1 S2 ... SK
B11 B12 ... B1K
B21 B22 ... B2K
:
BN1 BN2 ... BNK
N and K indicate the number of family members and the number of blood types respectively.
Si is an integer that indicates the amount of blood of the i-th blood type that is in a fridge.
Bij is an integer that indicates the amount of blood of the j-th blood type that the i-th vampire uses.
The end of input is indicated by a case where N = K = 0. You should print nothing for this data set.
Output
For each set, print "Yes" if everyone's dinner can be prepared using blood in a fridge, "No" otherwise (without quotes).
Example
Input
2 3
5 4 5
1 2 3
3 2 1
3 5
1 2 3 4 5
0 1 0 1 2
0 1 1 2 2
1 0 3 1 1
0 0
Output
Yes
No | 7 | 0 | #include<iostream>
using namespace std;
int main(){
int N,K,blood_sum[100],blood_num[100],blood;
bool flag;
while(1){
cin >>N>>K;
if(N == 0 && K == 0)break;
flag=0;
for(int i=0 ; i < 100 ; i++)blood_sum[i]=0;
for(int i=0 ; i < K ; i++)cin >>blood_num[i];
for(int i=0 ; i < N ; i++){
for(int j=0 ; j < K ; j++){
cin >>blood;
blood_sum[j]+=blood;
}
}
for(int i=0 ; i < K ; i++){
if(blood_sum[i] > blood_num[i]){
flag=1;
break;
}
}
if(flag == 1){
cout <<"No"<<endl;
}else{
cout <<"Yes"<<endl;
}
}
return 0;
} | CPP |
Subsets and Splits
No saved queries yet
Save your SQL queries to embed, download, and access them later. Queries will appear here once saved.