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 <cstdio> #include <algorithm> using namespace std; int main() { int i, n, m; int sum, array[1024]; while (1){ scanf("%d %d", &n, &m); if (!n && !m){ break; } for (i = 0; i < n; i++){ scanf("%d", &array[i]); } sort(array, array + n); reverse(array, array + n); for (i = 0, sum = 0; i < n; i++){ if ((i + 1) % m != 0 || n - (i / m * m) < m){ sum += array[i]; } } printf("%d\n", sum); } 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 <fstream> #include <algorithm> #include <cassert> #include <cctype> #include <complex> #include <cstdio> #include <map> #include <math.h> #include <queue> #include <set> #include <stack> #include <string> #include <vector> using namespace std; #define rep(i,n) for(int i=0;i<n;i++) int n,m,p[1000]; int main(){ while(cin>>n>>m&&n){ rep(i,n)cin>>p[i]; sort(p,p+n,greater<int>()); int ans=0; rep(i,n)if((i+1)%m)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 <iostream> #include <algorithm> #include <vector> using namespace std; int main() { int n, m; while(cin >> n >> m, n || m) { vector<int> v; for(int i = 0; i < n; i++) { int tmp; cin >> tmp; v.push_back(tmp); } sort(v.rbegin(), v.rend()); int res = 0; for(int i = 0; i < v.size(); i++) { if((i+1) % m) res += v[i]; } cout << res << 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(){ int i,j,n,m,a[1000],ans; while(1){ cin >> n >> m; if(n == 0 && m == 0) break; for(i=0;i<n;i++) cin >> a[i]; sort(a,a+n); ans = 0; j = 1; for(i=n-1;i>=0;i--){ if(j == m) j = 0; else ans += a[i]; j++; } cout << ans << 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 <list> int main() { int num,bag,sum; while(std::cin >> num >> bag){ if(num!=0 && bag!=0){ std::list<int> beg; for(int i=0;i<num;++i){ int price; std::cin >> price; beg.push_back(price); } beg.sort(std::greater<int>()); sum=0; for(int i=1;beg.empty()!=true;i++){ if(i%bag != 0){ sum+=beg.front(); } beg.pop_front(); } 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
#include<bits/stdc++.h> using namespace std; int main(void){ int n,m,roop=0,ans[100]; while(cin>>n>>m&&n!=0&&m!=0){ int p[n],sum=0,h=n/m; for(int i=0;i<n;i++){ cin>>p[i]; sum+=p[i]; } sort(p,p+n); for(int i=1;i<=h;i++){ sum-=p[n-m*i]; } ans[roop]=sum; roop++; } for(int i=0;i<roop;i++){ cout<<ans[i]<<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 data[1010]; int n,m; while(cin>>n>>m && n &&m){ for(int i=0;i<n;i++){ cin>>data[i]; } sort(data,data+n,greater<int>()); int ans=0; for(int i=0;i<n;i++){ if((i+1)%m!=0)ans+=data[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> int main(){ std::priority_queue<int> p; int n, m; int price; while(std::cin >> n >> m){ int sum_price = 0; if(n == 0 && m == 0) break; //input for(int i = 0; i < n; ++i){ std::cin >> price; p.push(price); } //袋詰め while(!p.empty()){ for(int i = 1; i <= m && !p.empty(); ++i){ if(i != m){ sum_price += p.top(); p.pop(); } else{ p.pop(); } } } std::cout << sum_price << std::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> #include <algorithm> using namespace std; int main(){ while (1){ int i,m,n,sum=0; int L[1000]; scanf("%d %d",&n,&m); if (n==0 && m==0) return 0; for (i=0;i<n;i++){ scanf("%d",&L[i]); sum+=L[i]; } sort(L,L+n); for (i=n-m;i>=0;i-=m) sum-=L[i]; printf("%d\n",sum); } }
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
# -*- coding: utf-8 -*- while 1: try: n, m = map(int, input().split()) if n == 0: break p = sorted(list(map(int, input().split()))) p.reverse() for i in range(m - 1, n, m): p[i] = 0 print(sum(p)) except: break
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<stdio.h> int main(){ int m,n,a[1000],i,k,st,c; while(1){ c=0; scanf("%d%d",&n,&m); if(n==0&&m==0)break; k=n; for(i=0;i<n;i++){ scanf("%d",&a[i]); } while(k!=0){ for(i=1;i<k;i++){ if(a[i-1]>a[i]){ st=a[i]; a[i]=a[i-1]; a[i-1]=st; } } k--; } for(i=n;i>=0;i-=m){ a[i]=0; } for(i=0;i<n;i++){ c+=a[i]; } printf("%d\n",c); } 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 <vector> #include <algorithm> using namespace std; int main() { int n, m; while (cin >> n >> m, n|m) { vector<int> ps(n); for (int i = 0; i < n; i++) { cin >> ps[i]; } sort(ps.begin(), ps.end(), greater<int>()); int ans = 0; for (int i = 0; i < n; i++) { if ((i+1) % m != 0) { ans += ps[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<bits/stdc++.h> using namespace std; #define lp(i,n) for(int i=0;i<n;i++) int main(){ while(1){ int n,m; cin>>n>>m; if(n==0&& m==0) break; int a[1000]; lp(i,n){ cin>>a[i]; } sort(a,a+n); reverse(a,a+n); int ans=0; lp(i,n){ if((i+1)%m==0) continue; else ans+=a[i]; } cout<<ans<<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
// 0227 #include <iostream> #include <vector> #include <algorithm> using namespace std; int main(){ while(1){ int n, m; vector<int> ve; cin>>n>>m; if((n == 0) && (m == 0 )) break; for(int i=0;i<n;i++){ int c; cin>>c; ve.push_back(c); } sort(ve.begin(), ve.end()); int cost = 0; for(int i=1;i<=n;i++) if(i%m != 0) cost += ve[n-i]; cout<<cost<<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; int main() { int N, M; while (cin >> N >> M, N) { vector<int> p(N); int sum = 0; for (int i = 0; i < N; i++) { cin >> p[i]; sum += p[i]; } sort(p.begin(), p.end()); for (int i = N - M; i >= 0; i -= M) { sum -= p[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(void){ int n,m,p[1000]; while(1){ int 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; } 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; int main() { int n, m; int data[1001]; while( cin >> n >> m, n+m ) { for(int i=0; i<n; i++) { cin >> data[i]; } sort(data, data+n); int ans = 0; int cnt = 0; while( n > 0 ) { cnt++; n--; if( cnt == m ) { cnt = 0; continue; } ans += data[n]; } 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> #include <vector> using namespace std; typedef long long ll; int main() { int n,m,q; ll res; vector<ll> v; while(true) { cin >> n >> m; if(n == 0) break; v.clear(); res = 0; for(int i = 0; i < n; i++){ cin >> q; v.push_back(q); } sort(v.begin(), v.end(), greater<int>()); for(int i=0; i < n; i++) { if(i % m != m - 1) res += v[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<bits/stdc++.h> using namespace std; int main(){ int n, m; while(cin >> n >> m, n, m){ int pn[1000]; for(int i = 0; i < n; i++) cin >> pn[i]; sort(pn, pn+n); int nowm = 0, ans = 0; for(int i = n-1; i >= 0; i--){ nowm++; if(nowm == m) nowm = 0; else{ ans += pn[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<bits/stdc++.h> using namespace std; int main(){ int n,m; vector<int> p; while(true){ int ans = 0; cin >> n >> m; if(n + m == 0) break; p.resize(n); for(int i=0; i<n;++i){ cin >> p[i]; } sort(p.begin(), p.end()); reverse(p.begin(), p.end()); for(int i = m - 1; i < n; i += m){ p[i] = 0; } for(int i = 0; i < n; ++i){ ans += p[i]; } cout<<ans<<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.*; class Main { public static void main(String args[]) { try (Scanner sc = new Scanner(System.in)) { while (true) { int n = sc.nextInt(), m = sc.nextInt(), ans = 0; if (n == 0 && m == 0) { break; } int[] P = new int[n]; for (int i = 0; i < n; i++) { P[i] = sc.nextInt(); } Arrays.sort(P); for (int i = 0; i < n / 2; i++) { int tmp = P[i]; P[i] = P[n - i - 1]; P[n - i - 1] = tmp; } for (int i = 0; i < n; i++) { if (i % m != m - 1) { ans += P[i]; } } System.out.println(ans); } } } }
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 <algorithm> #include <iostream> #define rep(i, n) for (int i = 0; i < (n); i++) using namespace std; int n, m; int p[1003]; void solve() { sort(p, p + n); reverse(p, p+n); int ans = 0; rep(i, n) ans += p[i]; for (int i = 0; i + m - 1 < n; i += m) { ans -= p[i + m - 1]; } cout << ans << endl; } int main() { while (cin >> n >> m) { rep(i, n) cin >> p[i]; if (n == 0 && m == 0) break; solve(); } 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<cstdio> #include<algorithm> using namespace std; int main(){ while(1){ int n,m; scanf("%d%d",&n,&m); if(n == 0 && m == 0) break; int a[1001] = {0}; for(int i = 1; i <= n; i++){ scanf("%d",&a[i]); } sort(a+1,a+n+1); reverse(a+1,a+n+1); int sum = 0; for(int i = 1; i <= n; i++){ if(i % m == 0)continue; sum += a[i]; } printf("%d\n",sum); } 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.*; import static java.util.Arrays.*; class Main { int[] ns; int n, m; void run(){ Scanner in = new Scanner(System.in); for(;;){ n = in.nextInt(); m = in.nextInt(); if(n == 0) return; ns = new int[n]; for(int i=0; i<n; i++) ns[i] = in.nextInt(); System.out.println(solve()); } } int solve(){ int ans = 0; sort(ns); for(int i=0; i<n; i++)if(i%m != m-1) ans += ns[n-i-1]; return ans; } public static void main(String args[]){ new Main().run(); } }
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
import java.util.*; public class Main { public static void main ( String[] args ) { int n , m; Scanner sc = new Scanner(System.in); while ( true ) { int cost = 0; n = sc.nextInt(); m = sc.nextInt(); if ( n == 0 && m == 0 ) break; int[] deta = new int[1000]; for ( int i = 0; i < n; i++ ) deta[i] = sc.nextInt(); Arrays.sort(deta,0,n); int index = n - 1 , count = 1; for ( int i = index; i >= 0; i-- ) { for ( ; i > i - m; i-- ) { if ( i < 0 ) break; if ( count % m != 0 ) cost += deta[i]; count++; } } System.out.println(cost); } } }
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
import java.util.Scanner; class Main { public static void main(String args[]) { Scanner scan=new Scanner(System.in); while(true) { int n,m; n=scan.nextInt(); m=scan.nextInt(); if(n==0 && m==0)break; int p[]=new int[n]; for(int i=0;i<n;i++) { p[i]=scan.nextInt(); } for(int i=0;i<n-1;i++) { for(int j=n-1;j>i;j--) { if(p[j]>p[j-1]) { int t=p[j-1]; p[j-1]=p[j]; p[j]=t; } } } int sum=0; int j=0; for(int i=1;i<=n;i++) { if(i%m!=0)sum+=p[i-1]; } 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 <algorithm> #include <vector> #include <numeric> #include <functional> using namespace std; #define rep(i,n) for(int i=0;i<n;i++) #define pb push_back int main() { while(1) { int n, m; scanf("%d %d", &n, &m); if(n == 0 && m == 0) break; vector<int> p; rep(i,n) { int t; scanf("%d", &t); p.pb(t); } sort(p.begin(), p.end(), greater<int>()); int sum = 0; rep(i,n/m) { p[(i + 1) * m - 1] = 0; } printf("%d\n", accumulate(p.begin(), p.end(), 0)); } 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
# try-except is necessary for avoiding Runtime Error while 1: try: n,m=map(int,raw_input().split()) if n==0:break v=sorted(map(int,raw_input().split()))[::-1] for i in range(m-1,n,m): v[i]=0 print sum(v) except: pass
PYTHON
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; int main(){ int N,M; while(cin >> N >> M, N != 0){ vector<int> p(N); for(int i = 0; i < N; i++) cin >> p[i]; sort(p.rbegin(), p.rend()); int ans = 0; for(int i = 0; i < N; i++){ if((i+1) % M) 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<iostream> #include<algorithm> #include<cstring> using namespace std; int main(){ int n,m,p; int d[1001]; int ans; while(true){ cin >> n >> m; if(!n && !m) break; memset(d,0,sizeof(d)); p = -1; ans = 0; for(int i=0;i<n;i++) cin >> d[i]; sort(d,d+n); reverse(d,d+n); for(int i=0;i<n;i++){ if(p+m == i) p += m; else ans += d[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 <vector> #include <algorithm> int main() { int n, m; std::cin >> n >> m; while (n != 0 && m != 0) { int whole_price = 0; std::vector<int> vegi(n); for (auto &v : vegi) std::cin >> v; std::sort(vegi.begin(), vegi.end()); for (auto i = 1; i <= n; ++i) { whole_price += (i % m == 0) ? 0 : vegi[n - i]; } std::cout << whole_price << std::endl; std::cin >> n >> m; } }
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, p; int data[1000]; 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); int sum=0; for(int i=n, count=0;i>=0;i--, count++){ if(count%m!=0){ sum+=data[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
import java.io.*; import java.math.BigInteger; import java.util.*; /** * @author yoshikyoto */ class Main extends MyUtil{ public static ArrayList<ArrayList<Integer>> g; public static void main(String args[]) throws Exception{ while(true){ int in[] = readIntMap(); int n = in[0], m = in[1]; if(in[0] == 0 && in[1] == 0) return; int p[] = readIntMap(); dsort(p); int ans = 0; for(int i = 0; i < n; i++){ if((i+1) % m == 0) continue; ans += p[i]; } p(ans); } } } /** * 整数を数え上げたりするクラス * new Prime(int n) でnまでエラトステネスの篩を実行。 * @author yoshikyoto * @param a[i] iが素数の時true * @param count[i] i以下の素数の数 */ class Prime{ boolean[] a; int[] count; Prime(int n){ a = new boolean[n+1]; a[0] = false; a[1] = false; for(int i = 2; i <= n; i++) a[i] = true; // ふるい for(int i = 2; i < (n - 3) / 2; i++) if(a[i]) for(int j = 2; j * i <= n; j++) a[j * i] = false; // 数え上げ count = new int[n+1]; count[0] = 0; for(int i = 1; i <= n; i++){ int gain = 0; if(a[i]) gain = 1; count[i] = count[i-1] + gain; } } } class AI extends ArrayList<Integer>{} class SI extends Stack<Integer>{} class HMI<E> extends HashMap<E, Integer>{ ArrayList<E> keyArray = new ArrayList<E>(); public void add(E key){add(key, 1);} public void add(E key, Integer value){ if(containsKey(key)){value += get(key); }else{keyArray.add(key);} put(key, value); } } class HMSI extends HMI<String>{} class Q<E> extends ArrayDeque<E>{ public void push(E item){add(item);} public E pop(){return poll();} } class QS extends Q<String>{} class QI extends Q<Integer>{} class MyUtil extends MyIO{ public static long start_time = 0; public static void start(){start_time = System.currentTimeMillis();} public static void end(){ if(start_time == 0) return; long time = System.currentTimeMillis() - start_time; if(DEBUG) p(time + "ms"); } public static int digit(int n){return String.valueOf(n).length();} public static String reverse(String s){ StringBuffer sb = new StringBuffer(s); return sb.reverse().toString(); } public static void sort(int[] a){Arrays.sort(a);} public static void dsort(int[] a){ Arrays.sort(a); int l = a.length; for(int i = 0; i < l/2; i++){ int tmp = a[i]; a[i] = a[l-1-i]; a[l-1-i] = tmp; } } public static void sleep(int t){try{Thread.sleep(t);}catch(Exception e){}} public static int sum(int[] a){int s = 0; for(int i = 0; i < a.length; i++)s+=a[i]; return s;} public static int[] cp(int[] a){ int[] b = new int[a.length]; for(int i = 0; i < a.length; i++) b[i] = a[i]; return b; } } class MyIO extends MyMath{ static Scanner sc = new Scanner(new InputStreamReader(System.in)); public static char scNextChar(){return sc.next().charAt(0);} static BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); public static boolean DEBUG = false; public static int[] readIntMap() throws IOException{return parseInt(readLine().split(" "));} public static String readLine() throws IOException{return br.readLine();} public static int readInt() throws IOException{return Integer.parseInt(br.readLine());} public static void p(Object o){System.out.println(o.toString());} public static void pr(Object o){System.out.print(o.toString());} public static void d(Object o){if(DEBUG)System.out.println(o.toString());} public static void dr(Object o){if(DEBUG)System.out.print(o.toString());} public static void da(Object[] o){if(DEBUG)System.out.println(Arrays.toString(o));} public static void da(int[] arr){if(DEBUG)System.out.println(Arrays.toString(arr));} public static void da(double[] arr){if(DEBUG)System.out.println(Arrays.toString(arr));} public static void da(boolean[] arr){if(DEBUG)System.out.println(Arrays.toString(arr));} public static int[] parseInt(String[] arr){ int[] res = new int[arr.length]; for(int i = 0; i < arr.length; i++)res[i] = Integer.parseInt(arr[i]); return res; } public static double[] parseDouble(String[] arr){ double[] res = new double[arr.length]; for(int i = 0; i < arr.length; i++)res[i] = Double.parseDouble(arr[i]); return res; } public static boolean[] parseBool(String[] arr){ int[] t = parseInt(arr); boolean[] res = new boolean[t.length]; for(int i = 0; i < t.length; i++){ if(t[i] == 1){res[i] = true; }else{res[i] = false;} } return res; } public static int parseInt(Object o){return Integer.parseInt(o.toString());} } class MyMath{ /** * 弧度法の角度を入力してsinの値を返す(Math.sin の入力はラジアン) */ public static double sin(int r){return Math.sin(Math.toRadians(r));} /** * 弧度法の角度を入力してcosの値を返す(Math.sin の入力はラジアン) */ public static double cos(int r){return Math.cos(Math.toRadians(r));} public static int max(int a, int b){return Math.max(a, b);} public static int min(int a, int b){return Math.min(a, b);} public static boolean isCross(int x1, int y1, int x2, int y2, int x3, int y3, int x4, int y4){ // 並行な場合 int m = (x2-x1)*(y4-y3)-(y2-y1)*(x4-x3); if(m == 0) return false; // 媒介変数の値が0より大きく1以下なら交差する、これは問題の状況によって変わるかも。 double r =(double)((y4-y3)*(x3-x1)-(x4-x3)*(y3-y1))/m; double s =(double)((y2-y1)*(x3-x1)-(x2-x1)*(y3-y1))/m; return (0 < r && r <= 1 && 0 < s && s <= 1); } public static boolean isParallel(int x1, int y1, int x2, int y2, int x3, int y3, int x4, int y4){ if((x2-x1)*(y4-y3) == (y2-y1)*(x4-x3)) return true; else return false; } public static double sq(double d){return d*d;} public static int sq(int i){return i*i;} public static int sqdist(int x1, int y1, int x2, int y2){ return sq(x1-x2) + sq(y1-y2);} public static double sqdist(double x1, double y1, double x2, double y2){ return sq(x1-x2) + sq(y1-y2);} public static double dist(int x1, int y1, int x2, int y2){ return Math.sqrt(sqdist(x1, y1, x2, y2));} public static double dist(double x1, double y1, double x2, double y2){ return Math.sqrt(sqdist(x1, y1, x2, y2));} }
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 <vector> #include <algorithm> int main(){ int i,n,m,x; for(;scanf("%d%d",&n,&m),n;printf("%d\n",x)){ std::vector<int>v; for(i=0;i<n;i++)scanf("%d",&x),v.push_back(x); std::sort(v.begin(),v.end()); for(x=i=0;i<n;i++)x+=(i%m==n%m)?0:v[i]; } }
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.Scanner; class Main { public static void main(String args[]) { Scanner scan=new Scanner(System.in); while(true) { int n,m; n=scan.nextInt(); m=scan.nextInt(); if(n==0 && m==0)break; int p[]=new int[n]; for(int i=0;i<n;i++) { p[i]=scan.nextInt(); } for(int i=0;i<n-1;i++) { for(int j=n-1;j>i;j--) { if(p[j]>p[j-1]) { int t=p[j-1]; p[j-1]=p[j]; p[j]=t; } } } int sum=0; int j=0; for(int i=0;i<n;i++) { if(j!=m-1) { sum+=p[i]; j++; } else if(j==m-1)j=0; } 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<iostream> #include<vector> #include<algorithm> using namespace std; #define REP(i,b,n) for(int i=b;i<n;i++) #define rep(i,n) REP(i,0,n) #define ALL(c) (c).begin(),(c).end() #define pb push_back int main(){ int n,m; while(cin>>n>>m && n){ vector<int> a(n); rep(i,n)cin>>a[i]; sort(ALL(a));reverse(ALL(a)); int ans=0; int cnt=1; rep(i,n){ if (cnt == m){ cnt=0; } else ans+=a[i]; cnt++; } cout << ans << endl; } return false; }
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<algorithm> #include<iostream> #include<vector> int main() { int n, m; while( std::cin >> n >> m, n | m ) { std::vector<int> v( n ); for( int i = 0; i != n; ++i ) { int p; std::cin >> p; v.push_back( p ); } std::sort( v.rbegin(), v.rend() ); int ans = 0; for( int i = 0; i != n; ++i ) if( ( i + 1 ) % m ) ans += v[i]; std::cout << ans << 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
#include<iostream> #include<algorithm> #include<functional> int *v,m,n,ans=0; int main(){ while(true){ std::cin >> n >> m; if(!n && !m) return 0; v = new int[n]; for(int i=0 ;i<n; i++) std::cin >> v[i]; std::sort(v,v+n,std::greater<int>()); if(m!=1) for(int i=0; i<n; i++) if(!((i+1)%m == 0 && (i+1) >= m)) ans += v[i]; std::cout << ans << std::endl; delete[] v; ans = 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 <queue> int main(){ int n,m; while(std::cin >> n >> m){ if(n == 0 && m == 0){ break; } std::priority_queue<int> vegetable; int each_price; for(int i = 0; i < n; ++i){ std::cin >> each_price; vegetable.push(each_price); } int sum_price = 0; for(int i = 0; i < n; ++i){ if((i % m) != (m - 1)){ sum_price += vegetable.top(); } vegetable.pop(); } std::cout << sum_price << 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
#include <bits/stdc++.h> #define FOR(v, s, t) for(int v = s; v < t; ++v) using namespace std; int main(){ int n, m, min; vector< int > p; while(cin >> n >> m, n){ p.resize(n); FOR(i, 0, n) cin >> p[i]; sort(p.begin(), p.end()); reverse(p.begin(), p.end()); min = 0; FOR(i, 0, n){ if((i + 1) % m != 0){ min += p[i]; } } cout << min << 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<vector> using namespace std; int main() { int n,m; for(;cin>>n>>m,n;) { vector<int> price; for(int i=0;i<n;i++) { int tmp; cin>>tmp; price.push_back(tmp); } sort(price.begin(),price.end()); int ans=0; int cnt=1; for(int i=n-1;i>=0;i--) { if(cnt==m) cnt=1; else { ans+=price[i]; cnt++; } } 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
#define _USE_MATH_DEFINES #include "bits/stdc++.h" #define EPS 1e-10 using namespace std; typedef long long llong; int main() { int n, m; while (cin >> n >> m, m) { vector<int>p(n); for (int i = 0; i < n; i++)cin >> p[i]; sort(p.rbegin(), p.rend()); int sum = 0; for (int i = 0; i < n; i++) { if ((i + 1) % m == 0)continue; sum += p[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 m, n; while(1){ cin >> n >> m; if(n == 0 && m == 0)break; int data[n]; for(int i = 0; i < n; i++){ cin >> data[i]; } sort(data, data+n); reverse(data, data+n); for(int i = m-1; i < n - (n%m); i+=m){ data[i] = 0; } int sum = 0; for(int i = 0; i < n; i++){ sum += data[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 <queue> int main(){ std::priority_queue<int> price; int n,m; while(std::cin >> n >> m){ int sum = 0; if(n == 0 && m == 0){ break; } for(int i = 0; i < n; ++i){ int temp; std::cin >> temp; price.push(temp); } for(int i = 1; i <= n; ++i){ if(i%m != 0){ sum += price.top(); } price.pop(); } 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
#include <stdio.h> #include <algorithm> using namespace std; const int N=1e5+10; int main(){ int n,m,a[N],ans; while(true){ scanf("%d%d",&n,&m); if(n==0&&m==0)return 0; ans=0; for(int i=0;i<n;i++)scanf("%d",&a[i]); sort(a,a+n); reverse(a,a+n); for(int i=0;i<n;i++)if((i+1)%m!=0)ans+=a[i]; printf("%d\n",ans); } }
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 <algorithm> #include <iostream> #include <vector> #include <string> #include <cmath> using namespace std; int main(){ int n,m,v,ans; while(1){ vector<int> b ; ans=0; cin >> n >> m ; if( (n==0) && (m==0) ){ return 0; } for(int i=0;i<n;i++){ cin >> v; ans += v; b.push_back(v); } sort(b.begin(),b.end()); reverse(b.begin(),b.end()); for(int i=m-1;i<n;i+=m){ ans -= b[i]; } cout << ans << "\n"; } }
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> #include<numeric> using namespace std; int main(){ while(1){ int n, m; cin >> n >> m; if(n + m == 0) break; vector<int> p(n); for(int i = 0; i < n; i++) cin >> p[i]; sort(p.begin(), p.end()); for(int i = n-m; i >= 0; i -= m){ p[i] = 0; } cout << accumulate(p.begin(), p.end(), 0) << 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
# Aizu Problem 0227: Thanksgiving import sys, math, os, bisect # read input: PYDEV = os.environ.get('PYDEV') if PYDEV=="True": sys.stdin = open("sample-input.txt", "rt") while True: n, m = [int(_) for _ in input().split()] if n == m == 0: break prices = sorted([int(_) for _ in input().split()], reverse=True) for i in range(m - 1, n, m): prices[i] = 0 print(sum(prices))
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 <algorithm> #include <vector> int main(){ int n, m; while(std::cin >> n >> m, n){ int total = 0; std::vector<int> pvec; for(int i=0;i<n;i++){ int p; std::cin >> p; pvec.push_back(p); total += p; } std::sort(pvec.begin(), pvec.end(), std::greater<int>()); int i = 1, discount = 0; for(;i*m<=n;i++){ discount += pvec[i*m-1]; } std::cout << total - discount << std::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> #include<vector> using namespace std; int main(){ int n,m,p; while(true){ cin >> n >> m; if(n+m == 0)break; vector<int> vec; for(int i=0;i<n;i++){ cin >> p; vec.push_back(p); } sort(vec.begin(),vec.end(),greater<int>() ); int sum = 0,cnt=1; for(int i=0;i<vec.size();i++){ if(cnt%m == 0){ cnt = 1; continue; } sum+=vec[i]; cnt++; } 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 ; int main(){ int n , m ; int c[1010] ; while( cin >> n >> m , n , m ){ for( int i=0 ; i<n ; i++ ) cin >> c[i] ; sort(c,c+n,greater<int>()) ; int sum = 0 ; for( int i=0 ; i<n ; i++ ){ if( (i+1)%m ) sum += c[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 <bits/stdc++.h> using namespace std; using ll = long long; using pii = pair<int, int>; int n, m; int p[1010]; int main() { cin.tie(0); ios_base::sync_with_stdio(false); cout << fixed << setprecision(10); while (cin >> n >> m, n) { for (int i = 0; i < n; i++) { cin >> p[i]; } sort(p, p + n, greater<int>()); int ans = 0; for (int i = 0; i < n; i++) { if ((i + 1) % m == 0) continue; ans += p[i]; } cout << ans << 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; int main(){ while(1){ int n,m; int p[10000]; int sum=0; cin>>n>>m; if(n==0 && m==0) break; for(int i=0;i<n;i++){ cin>>p[i]; } for(int i=0;i<n;i++){ for(int j=0;j<n-1;j++){ if(p[j]<p[j+1]) swap(p[j],p[j+1]); } } for(int i=0;i<n;i++){ if(i%m==m-1) p[i]=0; } for(int i=0;i<n;i++){ sum+=p[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 p[10000]; while(cin >> n >> m){ if(n == 0 && m == 0) break; for(int i=0;i<n;i++){ cin >> p[i]; } int sum = 0; int count = 1; sort(p,p+n); for(int i=n-1;i>=0;i--){ if(count%m!=0) sum += p[i]; count++; } 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> using namespace std; int main(){ int n,m; while(1){ int ans=0,p[10001]={}; cin>>n>>m; if(n+m==0)break; for(int i=1;i<=n;i++){ cin>>p[i]; } for(int j=0;j<n;j++) for(int i=1;i<=n;i++) if(p[i]<p[i+1])swap(p[i],p[i+1]); for(int i=1;i<=n;i++){ if(i%m==0)p[i]=0; ans+=p[i]; } cout<<ans<<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; bool cmp(const int &p1, const int &p2) { return p1 > p2; } int main() { int n, m, sum; int price[1000]; while (cin >> n >> m, n) { memset(price, 0, sizeof(price)); for (int i = 0; i < n; ++i) { cin >> price[i]; } sort(price, price + n,cmp); sum = 0; for (int i = 0; i < n; ++i) { //cout << price[i] << " "; if ((i + 1) % m == 0) { price[i] = 0; } sum += price[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 <vector> #include <algorithm> int main(){ int n,m; int p; while(true){ std::cin >> n >> m; if(n == 0 && m == 0){ break; } std::vector<int> price; for(int i=0; i<n ;++i){ std::cin >> p; price.push_back(p); } //sort in descending order std::sort(price.begin(), price.end(), std::greater<int>()); int i=1; //counter int sum=0; for(int x : price){ if(i%m != 0){ sum += x; } ++i; } //output std::cout << sum << std::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 i,s,m,n,d[1000]; while(cin >> n >> m && n!=0) { for (i=0,s=0;i<n;i++) { cin >> d[i]; s+=d[i]; } sort(d,d+n,greater<int>()); for (i=m-1;i<n;i+=m) s-=d[i]; cout << s << 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; while(cin>>n>>m,n){ int a[1000],ans=0; for(int i=1;i<=n;i++){ cin>>a[i]; } sort(a+1,a+n+1); reverse(a+1,a+n+1); for(int i=1;i<=n;i++){ if(i%m!=0)ans+=a[i]; } cout<<ans<<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
// 2011/01/08 Tazoe #include <iostream> using namespace std; int main() { while(true){ int n, m; cin >> n >> m; if(n==0&&m==0) break; int p[1000]; for(int i=0; i<n; i++) cin >> p[i]; for(int i=0; i<n-1; i++) for(int j=i+1; j<n; j++) if(p[i]<p[j]){ int tmp = p[i]; p[i] = p[j]; p[j] = tmp; } for(int i=m-1; i<n; i+=m) p[i] = 0; int sum = 0; for(int i=0; i<n; i++) sum += p[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> #include<functional> using namespace std; int main(){ int n,m,a[11111]; while(1){ cin >> n >> m; if(n == 0 && m == 0) break; int total = 0; for(int i=0;i<n;i++){ cin >> a[i]; total += a[i]; } sort(a,a+n,greater<int>() ); for(int i=m-1;i<n;i+=m) total -= a[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> using namespace std; #define rep(i,n) for(int i=0;i<n;i++) int main(){ int n,m; while(cin >> n >> m , n){ vector<int> data(n); int ret = 0; rep(i,n)cin >> data[i]; sort(data.begin(),data.end(),greater<int>()); rep(i,n){ if((i+1)%m==0)continue; ret += data[i]; } cout << ret << 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 <bits/stdc++.h> using namespace std; #define rep(i, j) for(int i = 0; i < j; ++i) #define INF (1 << 30) #define MAX 10000 int main() { int n, m, p[MAX]; while(cin >> n >> m, n || m) { int total = 0; rep(i, n) { cin >> p[i]; total += p[i]; } sort(p, p + n); for(int i = n - m; i >= 0; i -= m) total -= p[i]; cout << total << 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 <string> #include <algorithm> #define rep(i,n) for(int i=0;i<n;++i) using namespace std; int a[1010]; int main(){ int n,m; while(cin >> n >> m,n){ rep(i,n) cin >> a[i]; int sum=0; rep(i,n) sum+=a[i]; sort(a,a+n); for(int i=n-m;i>=0;i-=m) sum-=a[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 <vector> #include <algorithm> int main(){ int n, m; while(std::cin >> n >> m){ if(n == 0 && m == 0){ break; } std::vector<int> price(n, 0); int sum_price = 0; //全ての値段の合計 for(int i = 0 ; i < n ; ++i){ std::cin >> price[i]; sum_price += price[i]; } std::sort(price.begin(), price.end(), std::greater<int>()); for(int i = m - 1 ; i < n ; i += m){ sum_price -= price[i]; } std::cout << sum_price << 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
import java.util.ArrayList; import java.util.Collections; import java.util.Scanner; class Main{ public static void main(String[] args){ Scanner sc = new Scanner(System.in); ArrayList<Integer> list = new ArrayList<Integer>(); int n,m,sum,count; while(true){ list.clear(); n = sc.nextInt(); m = sc.nextInt(); if(n == 0 && m == 0)break; for(int i = 0; i < n; i++) list.add(sc.nextInt()); Collections.sort(list); sum = count = 1; for(int i = n; i > 0; i--){ if(count != m) sum += list.get(i-1); else count = 0; count++; } System.out.println(sum-1); } sc.close(); } }
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 <cstdio> #include <algorithm> #include <array> #include <vector> #include <functional> using namespace std; int main() { while( true ) { int n, m; cin >> n >> m; if ( n == 0 && m == 0 ) break; vector<int> xs( n ); for ( int i = 0; i < n; i++ ) { cin >> xs[ i ]; } sort( xs.begin(), xs.end(), greater<int>() ); int sum = 0; for ( int i = 0; i < n; i++ ) { sum += ( (i + 1) % m == 0 ? 0 : xs[ 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 n,m,a[1000]; int main() { while(cin>>n>>m,n) { int ans=0; for(int i=0;i<n;i++) { cin>>a[i]; ans+=a[i]; } sort(a,a+n); for(int i=n-m;i>=0;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 <cstdio> #include <algorithm> using namespace std; int main() { int n, m; while (scanf("%d %d", &n, &m), n != 0 && m != 0){ int p[1024]; for (int i = 0; i < n; i++){ scanf("%d", &p[i]); } sort(p, p+n); reverse(p, p+n); for (int i = 0; i < n; i++){ if ((i + 1) % m == 0){ p[i] = 0; } } int sum = 0; for (int i = 0; i < n; i++){ sum += p[i]; } printf("%d\n", sum); } }
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.Scanner; class Main { public static void main(String[] args){ Scanner scan = new Scanner(System.in); int n, m; int[] bag; int p; int v, j; int ans; while(true){ n = scan.nextInt(); m = scan.nextInt(); if(n == 0 && m == 0)break; bag = new int[n]; ans = 0; for(int i = 0; i < n; i++){ p = scan.nextInt(); bag[i] = p; } v = 0; j = 0; for(int i = 1; i <= n - 1; i++){ v = bag[i]; j = i - 1; while(j >= 0 && bag[j] < v){ bag[j + 1] = bag[j]; j--; } bag[j + 1] = v; } for(int i = 0; i <= n/m; i++){ if(i != 0) bag[i * m - 1] = 0; } for(int i = 0; i < n; i++){ ans += bag[i]; } System.out.println(ans); } } }
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 <bits/stdc++.h> using namespace std; #define FOR(i, a, b) for(int i=(a); i<(b); i++) #define REP(i, n) FOR(i, 0, n) int main(){ while(1){ int n, m; cin>>n>>m; if(n==0) break; int a[n]; REP(i, n) cin>>a[i]; sort(a, a+n, greater<int>()); int sum = 0; REP(i, n) sum+=a[i]; for(int i=m-1; i<n; i+=m){ sum-=a[i]; } printf("%d\n", sum); } }
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(void) { int n,m; int res; while(1) { cin >> n >> m; if(n == 0 && m == 0) break; res = 0; int p[n]; for(int i = 0; i < n; i++) cin >> p[i]; stable_sort(p, p + n); for(int i = n-1; i >= 0; ) { for(int j = 0; j < m-1; j++) { if(i < 0) break; res += p[i]; i--; } 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
while True: try: n,m = list(map(int,input().split())) if n == 0 and m == 0: break amari = n % m yasai = list(map(int,input().split())) yasai.sort() s = 0 for i in range(n): if (i+1) % m > 0: s += yasai[-i-1] print(s) except: pass
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<stdio.h> #include<algorithm> using namespace std; int table[1000]; int main(){ int a,b; while(scanf("%d%d",&a,&b),a){ int sum=0; for(int i=0;i<a;i++){ scanf("%d",table+i); sum+=table[i]; } std::sort(table,table+a); for(int j=a-b;j>=0;j-=b)sum-=table[j]; printf("%d\n",sum); } }
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; int main() { int n, m; while(cin >> n >> m, n || m){ int p[1001]; for(int i = 0; i < n; i++) cin >> p[i]; sort(p, p + n, greater<int>()); int ans = 0; for(int i = 0; i < n; i++){ if((i+1)%m == 0) continue; ans += p[i]; } cout << ans << 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> #define r(i,n) for(i=0;i<n;i++) using namespace std; int main(){ int a,b,i; while(cin>>a>>b,a){ int c[a],s=0,k=0,p=0; r(i,a){cin>>c[i];p+=c[i];} sort(c,c+a); for(i=a-1;i>=0;i--){ k++; if(k==b){ s+=c[i]; k=0; } } cout<<p-s<<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 <bits/stdc++.h> using namespace std; int main() { while (true) { int n, m; cin >> n >> m; if (n==0 && m==0) { break; } int p[n]; int s = 0; for (int i=0; i<n; i++) { cin >> p[i]; s += p[i]; } sort(p, p+n, greater<int>()); for (int i=1; i*m-1<n; i++) { s -= p[i*m-1]; } cout << s << 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; int p[1000]; cin >> n >> m; while (n != 0 || m != 0) { for (int i = 0; i < n; i++) cin >> p[i]; sort(p, p + n, greater<int>()); int s = 0; for (int i = 0; i < n; i++) { if (i % m != m - 1) s += p[i]; } cout << s << endl; cin >> n >> m; } 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 argc, char const* argv[]) { int n,m; int place[1000]; while( cin >> n >> m && n != 0 ){ for( int i = 0;i < 1000;i++ ) place[i] = 0; for( int i = 0;i < n;i++ ) cin >> place[i]; sort( place, place + n, greater<int>() ); for( int i = 1;i * m - 1 < n;i++ ) place[i * m - 1] = 0; int answer = 0; for( int i = 0;i < n;i++ ) answer += place[i]; cout << answer << 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<cstdio> #include<algorithm> #include<string> using namespace std; int N,M; int P[1000]; int main() { while(true){ scanf("%d%d",&N,&M); if(N==0&M==0)break; for(int i=0;i<N;i++)scanf("%d",&P[i]); sort(P,P+N);reverse(P,P+N); int ans=0; for(int i=0;i<N;i++){ if(i%M!=M-1)ans+=P[i]; } printf("%d\n",ans); } 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
//48 #include<iostream> #include<algorithm> #include<functional> using namespace std; int main(){ for(int n,m;cin>>n>>m,n|m;){ int p[1000]; for(int i=0;i<n;i++){ cin>>p[i]; } sort(p,p+n,greater<int>()); int cost=0; int h=0; for(int i=0;i<n;i++){ h++; if(h%m){ cost+=p[i]; } } cout<<cost<<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; int main() { int n,m; while(cin>>n>>m,n,m){ int vege[1000]; for(int i=0;i<n;i++)cin>>vege[i]; sort(vege,vege+n); for(int i=1;n-m*i>=0;i++)vege[n-m*i]=0; for(int i=1;i<n;i++)vege[0]+=vege[i]; cout<<vege[0]<<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<algorithm> using namespace std; int main(){ while(1){ int sina[1000],n,m,sum=0; scanf("%d%d",&n,&m); if(n==0&&m==0)return 0; for(int i=0;i<n;i++){ scanf("%d",&sina[i]); sum+=sina[i]; } sort(sina,sina+n); for(int i=n-m;i>=0;i-=m){ sum-=sina[i]; } printf("%d\n",sum); } }
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 <numeric> #include <functional> int main(){ int n, m; while (std::cin >> n >> m, n || m){ int data[1001]; for (int i = 0; i < n; i++)std::cin >> data[i]; std::sort(data, data + n, std::greater<int>()); int ans = 0; for (int i = m - 1; i < n; i += m)ans += data[i]; ans = std::accumulate(data, data + n, 0) - ans; std::cout << ans << 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
#include<iostream> #include<algorithm> using namespace std; int main(void) { int n, m, p[10000]; while (cin >> n >> m) { if (n == 0 && m == 0) break; int sum = 0; 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
import java.util.*; class Main{ public static void main(String[] args){ Solve s = new Solve(); s.solve(); } } class Solve{ Solve(){} Scanner in = new Scanner(System.in); void solve(){ while(in.hasNext()){ int n = in.nextInt(), m = in.nextInt(); if(n == 0 && m == 0) return; int[] a = new int[n]; for(int i = 0; i < n; i++) a[i] = -in.nextInt(); Arrays.sort(a); int ans = 0; for(int i = 0; i < n; i++){ if((i + 1) % m != 0) ans -= a[i]; } System.out.println(ans); } } } // while(in.hasNext()){ // int n = in.nextInt(); // if(n == 0) return; // }
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
import java.util.Arrays; import java.util.Scanner; public class Main { public static void main(String[] args){ try(Scanner sc=new Scanner(System.in)){ while(sc.hasNext()) { int n=sc.nextInt(); int m=sc.nextInt(); if((n|m)==0) break; int[] p=new int[n]; for(int i=0; i<n; i++) { p[i]=sc.nextInt(); } Arrays.sort(p); int cost=0, count=0; for(int i=n-1; i>=0; i--) { count++; cost+=(count%m==0)?0:p[i]; } System.out.println(cost); } } } }
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 <queue> int main(){ std::priority_queue<int> price; int n,m; while(std::cin >> n >> m){ int sum = 0; if(n == 0 && m == 0){ break; } for(int i = 0; i < n; ++i){ int temp; std::cin >> temp; price.push(temp); } for(int i = 1; i <= n; ++i){ if(i%m != 0){ sum += price.top(); price.pop(); } else{ price.pop(); } } 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
#include <bits/stdc++.h> using namespace std; #define rep(i, n) for (int i = 0; i < (int)(n); i++) #define rrep(i, n) for (int i = (int)(n) - 1; i >= 0; i--) int n, m; int p[1010]; int main() { while (cin >> n >> m, n){ rep(i, n) cin >> p[i]; sort(p, p + n, greater<int>()); int res = 0; rep(i, n) res += p[i]; for (int i = m - 1; i < n; i += m){ res -= p[i]; } cout << res << 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 num,cap,price,i; while(std::cin >> num >> cap){ if(num == 0 && cap == 0){ break; } std::vector<int> vegetables; for(i=0; i<num; ++i){ std::cin >> price; vegetables.push_back(price); } sort(vegetables.begin(), vegetables.end(), std::greater<int>()); int sum = 0; i = 0; while(i < num){ if((i+1) % cap != 0){ sum += vegetables.at(i); } ++i; } std::cout << sum << std::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(void){ int n,m; while(std::cin >> n >> m && n!=0 && m!=0){ std::vector<int> veg; for(int i=0;i<n;i++){ int tmp; std::cin >> tmp; veg.push_back(tmp); } std::sort(veg.begin(),veg.end(),std::greater<int>()); int sum =0; for(int i=0;i<n;i++){ if((i+1)%m != 0){ sum += veg[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
#include <iostream> #include <algorithm> using namespace std; int main() { int n, m, p[1001]; while(1){ cin >> n >> m; if(n == 0 && m == 0){ break; } for(int i = 0; i < n; i++){ cin >> p[i]; } sort(p, p+n); int s=0; for(int i = n-1, j=1; i >= 0; i--, j++){ if(j == m){ j = 0; } else { s += p[i]; } } cout << s << 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<vector> #include<algorithm> using namespace std; int main() { int n, m, p, ans; vector<int> pv; while(1) { cin >> n >> m; if(!n&&!m) break; pv.clear(); ans = 0; for(int i=0; i<n; ++i) { cin >> p; pv.push_back(p); } sort(pv.begin(), pv.end(), greater<int>()); for(int i=0; i<n; ++i) { if(i%m<m-1) ans += pv[i]; } cout << ans << 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 <cstdio> #include <algorithm> using namespace std; int main(){ int n,m,p[1000]; while(scanf("%d%d",&n,&m), n != 0){ for(int i=0; i<n;i++){ scanf("%d",&p[i]); } sort(p,p+n); int sum = 0; int it = 0; for(int i = n-1; i >= 0; i--,it++){ if(it % m != m-1) sum += p[i]; } printf("%d\n",sum); } 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 <queue> int main(){ int n,m; while(std::cin >> n >> m){ if(n == 0 && m == 0){ break; } std::priority_queue<int> que; int vegetable; for(int i = 0; i < n; ++i){ std::cin >> vegetable; que.push(vegetable); } int price = 0; for(int i = 0; i < n; ++i){ if((i % m) != (m - 1)){ price += que.top(); } que.pop(); } std::cout << price << 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
import java.util.Scanner; public class Main{ public static void main(String[] args) { Scanner stdIn = new Scanner(System.in); while (stdIn.hasNext()) { int n = stdIn.nextInt(); int m = stdIn.nextInt(); if (n != 0 ||m != 0) { int a[] = new int[n]; for (int i = 0; i < n; i++) { a[i] = stdIn.nextInt(); } for (int i = 0; i < a.length - 1; i++) { for (int j = i + 1; j < a.length; j++) { if (a[j] > a[i]) { int temp = a[i]; a[i] = a[j]; a[j] = temp; } } } for (int i = 1; i < n + 1; i++) { if (i % m == 0) { a[i - 1] = 0; } } int b = 0; for (int i = 0; i < n; i++) { b += a[i]; } System.out.println(b); } } } }
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
import java.util.Scanner; import java.util.Arrays; public class Main{ public static void main(String[] args){ Scanner scan = new Scanner(System.in); while(scan.hasNext()){ int n = scan.nextInt(); int m = scan.nextInt(); if(n == 0 && m == 0){ break; } int[] p = new int[n]; int sum = 0; for(int i = 0;i < n;i++){ p[i] = scan.nextInt(); sum += p[i]; } Arrays.sort(p); for(int i = m-1;i < n;i+=m){ sum -= p[n-1-i]; } 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<iostream> #include<algorithm> using namespace std; int main(){ int n,m,a[1000],sum,dis,p; while(1){ sum=0; dis=0; cin >>n>>m; if( n == 0 && m == 0 )break; for(int i=0 ; i < n ; i++){ cin >>a[i]; sum+=a[i]; } sort(a,a+n); for(int i=n-m ; i >= 0 ; i-=m ){ dis+=a[i]; } p=sum-dis; cout <<p<<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 { static Scanner sc = new Scanner(System.in); public static void main(String[] args) { while(true){ int n = sc.nextInt(); int m = sc.nextInt(); if(n == 0 && m == 0){ break; } int[] vegetable = new int[n]; for(int i = 0; i < n; i++){ vegetable[i] = sc.nextInt(); } Arrays.sort(vegetable); System.out.println(getPrice(vegetable, m)); } sc.close(); } private static int getPrice(int[] v, int m){ int sum = 0; for(int i = 0; i < v.length; i++){ if((i + 1) % m != 0){ sum += v[v.length - 1 - i]; } } return 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
import sys f = sys.stdin while True: n, m = map(int, f.readline().split()) if n == 0: break vegitables = sorted(map(int, f.readline().split()), reverse=True) discount = sum(vi for i, vi in enumerate(vegitables) if (i + 1) % m == 0) print(sum(vegitables) - discount)
PYTHON3