Go: package main

import (
	"bufio"
	"os"
	"strings"
	"strconv"
	"sort"
	"fmt"
)

var scanner = bufio.NewScanner(os.Stdin)

func main() {
	for scanner.Scan() {
		buf := strings.Split(scanner.Text(), " ")
		n, _ := strconv.Atoi(buf[0])
		m, _ := strconv.Atoi(buf[1])
		if n == 0 && m == 0 {
			break
		}
		scanner.Scan()
		buf_ := strings.Split(scanner.Text(), " ")
		items := make([]int, n)
		for i := 0; i < n; i++ {
			items[i], _ = strconv.Atoi(buf_[i])
		}
		sort.Ints(items)
		sum := 0
		for _, v := range items {
			sum += v
		}
		for i := n-m; i >= 0; i -= m {
			sum -= items[i]
		}
		fmt.Println(sum)
	}
}

C++: #include <iostream>
#include <queue>
 
int main(){
	std::priority_queue<int> price;
	int n, m;
	int p;
	while(std::cin >> n >> m){
		int sum_price = 0;
		if(n == 0 && m == 0){
			break;
		}
		//各野菜の値段を入力、格納
		for(int i = 0; i < n; ++i){
			std::cin >> p;
			price.push(p);
		}
		//袋詰め
		while(!price.empty()){
			for(int i = 1; i <= m && !price.empty(); ++i){
				if(i != m){
					sum_price += price.top();
					price.pop();
				}
				else{ //最後に袋に入る品物は割引
					price.pop();
				}
			}
		}
		std::cout << sum_price << std::endl;
	}
}

C++: #include<bits/stdc++.h>
using namespace std;
int main(){
  int n,m,sum=0,d;
  int p[1001000]={};
  while(1){
    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);
    reverse(p,p+n);
    for(int i=1; i<n; i++){
      d = m*i-1;
      sum -= p[d];
    }
    cout << sum << endl;
  }
  return 0;
}

C++: #include <iostream>
#include <vector>
#include <algorithm>
#include <set>
#include <string>
#include <cmath>
#include <map>
#include <cstring>

#define REP(i, n) for (int i = 0; i < (n); i++)
#define FOR(i, init, n) for (int i = init; i < (n); i++)
#define ALL(obj) (obj).begin(), (obj).end()
#define RALL(obj) (obj).rbegin(), (obj).rend()
#define Cout(obj) cout << obj << endl
#define Size(obj) (int)(obj).size()
#define fcout cout << fixed << setprecision(10)
#define fi first
#define se second

using namespace std;
using ll = long long int;
using P = pair<int, int>;
using T = tuple<int, int, int>;
using edge = struct
{
    int to, cost;
};

const int MOD = 1e9 + 7;
const int iINF = 1e9;
const long long int llINF = 1e18;
const double PI = acos(-1.0);

const int dx[4] = {1, 0, -1, 0};
const int dy[4] = {0, 1, 0, -1};

int main()
{
    cin.tie(0);
    ios::sync_with_stdio(false);

    int N, M;
    while (cin >> N >> M, N)
    {
        vector<int> p(N);
        REP(i, N) { cin >> p[i]; }

        sort(RALL(p));

        int ans = 0;

        for (int i = 0; i < N;)
        {
            int sum = 0, cnt = 0;

            while (i < N && cnt < M)
            {
                sum += p[i++];
                cnt++;
            }

            if (cnt == M)
            {
                sum -= p[i - 1];
            }

            ans += sum;
        }

        Cout(ans);
    }

    return 0;
}

C++: #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;
}

C++: #include <iostream>
#include <vector>
#include <algorithm>

int main(){
    int n, m, p, sum;
    std::vector<int> price_list = {};
    std::vector<int> sum_list = {};    

    while(std::cin >> n >> m){
        if(n == 0 && m == 0){
            break;
        } else{
            sum = 0;
            for(int i = 0;i < n;++i){
                std::cin >> p;
                price_list.push_back(p);
                sum += p;
            }
            std::sort(price_list.begin(), price_list.end(), std::greater<int>());
            for(int i = 1;i <= n/m;++i){
                sum -= price_list.at(i * m - 1);
            }
            //std::cout << sum << std::endl;
            sum_list.push_back(sum);
        }
    }
    for(int i = 0;i < sum_list.size();i++){
        std::cout << sum_list.at(i) << std::endl;
    }
    return 0;
}

C++: #include <iostream>
#include <vector>
#include <algorithm>
#include <functional>
using namespace std;

int main()
{
  int n, m;
  while (cin >> n >> m) {
    if ((n|m) == 0)
      break;

    vector<int> v(n);
    for (int i = 0; i < n; ++i)
      cin >> v[i];
    while (v.size() % m != 0)
      v.push_back(0);
    sort(v.begin(), v.end(), greater<int>());

    int ans = 0;
    for (unsigned int i = 0; i < v.size(); i += m) {
      for (int j = 0; j < m-1; ++j)
	ans += v[i+j];
    }

    cout << ans << endl;
  }
  return 0;
}

C++: #include <algorithm>
#include <deque>
#include <functional>
#include <iostream>

using namespace std;

int main() {

	int n, m, j=0, x, min;
	deque<int> p;

	while(cin >> n >> m) {
		if(n==0&&m==0)
			break;
		int a=m-1;
		min=0;
		p.clear();
		for(int i=0; i<n; i++) {
			cin >> x;
			p.push_back(x);
		}
		sort(p.begin(), p.end(), greater<int>());
		for(int i=0; i<p.size(); i++) {
			(i==a) ? a+=m : min+=p[i];
		}
		cout << min << endl;
	}

	return 0;

}

C++: #include <iostream>
#include <vector>
#include <algorithm>

int main(){
    int n, m, p, sum;
    std::vector<int> price_list = {};

    while(std::cin >> n >> m){
        if(n == 0 && m == 0){
            break;
        } else{
            sum = 0;
            for(int i = 0;i < n;i++){
                std::cin >> p;
                price_list.push_back(p);
                sum += p;
            }
            std::sort(price_list.begin(), price_list.end(), std::greater<int>());
            for(int i = 1;i <= n/m;i++){
                sum -= price_list.at(i * m - 1);
            }
            std::cout << sum << std::endl;
        }
        
    }
}

C++: #include <iostream>
#include <vector>
#include <algorithm>

int main(void){
    std::vector<int> price;
    int num_vegetable, bag_capacity;
    while(std::cin >> num_vegetable >> bag_capacity){
        if(num_vegetable == 0 && bag_capacity == 0)
            break;
        for(int p, i = 0; i < num_vegetable; ++i){
            std::cin >> p;
            price.push_back(p);
        }
        
        std::sort(price.begin(), price.end(), std::greater<int>());

        int price_sum;
        for(int i = 0; i < num_vegetable; ++i){
            if((i + 1) % bag_capacity != 0)
                price_sum += price.at(i);
        }
        std::cout << price_sum << std::endl;
    }
}

C++: #include<cstdio>
#include<iostream>
#include<algorithm>
using namespace std;

int main(void)
{
	while (1)
	{
		int n, m, p[1000], sum = 0;
		cin >> n >> m;
		if (n == 0 && m == 0)break;
		for (int i = 0; i < n; i++)
		{
			cin >> p[i];
			sum += p[i];
		}
		sort(p, p + n);
		for (int i = n - m; i >= 0; i -= m)
		{
			sum -= p[i];
		}
		cout << sum << endl;
	}
	
}

C++: #include <iostream>
#include <sstream>
#include <fstream>
#include <iomanip>
#include <numeric>
#include <map>
#include <string>
#include <vector>
#include <cmath>
#include <queue>
#include <algorithm>
using namespace std;
typedef long long ll;
typedef pair<int, int> P;
typedef pair<int, P> PP;
typedef pair<P,P> P2;
const int INF = 1 << 30;
const double EPS = 1E-9;

int vege[1000];

bool comp(int a, int b){
	return a > b;
}

int main(){
	int n, m;
	while(cin >> n >> m && (n || m)){
		for(int i = 0; i < n; i++){
			cin >> vege[i];
		}
		sort(vege, vege + n, comp);
		int cost = 0;
		for(int i = 0; i < n; i++){
			if((i + 1) % m == 0) continue;
			cost += vege[i];
		}
		cout << cost << endl;
	}
	return 0;
}