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 <vector>
#include <algorithm>

int main(){
	std::vector<int> vegetables;
	int num,cap,price,i;

	while(std::cin >> num >> cap){

		if(num == 0 && cap == 0){
			break;
		}

		int sum = 0;

		for(i=0; i<num; ++i){
			std::cin >> price;
			vegetables.push_back(price);
		}

		sort(vegetables.begin(), vegetables.end(), std::greater<int>());

		i = 0;

		while(i < num){

			if((i+1) % cap != 0){
				sum += vegetables.at(i);
			}

			++i;
		}

		std::cout << sum << std::endl;
	}

}

C++: #include <iostream>
#include <algorithm>
using namespace std;
int main(){
  int n,m;
  while(cin >> n >> m , n + m){
    int yasai[1000] = {0};

    for(int i = 1 ; i <= n ; i++){
      cin >> yasai[i];
    }

    sort(yasai,yasai+(n+1),greater<int>());

    for(int i = n ; i >0 ; i--){
      yasai[i] = yasai[i-1];
    }
    int sum = 0;
    for(int i = 1 ; i <= n ; i++){
      if(i%m != 0)sum+=yasai[i];
    }
    cout << sum << endl;
  }
}

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

int main(){
	int n, m, tmp;
	while(cin >> n >> m){
		vector<int> v;
		int ans = 0;
		if(n == 0 && m == 0) break;
		for(int i = 0; i < n; i++){
			cin >> tmp;
			v.push_back(tmp);			
		}
		sort(v.begin(), v.end(), greater<int>());
		for(vector<int>::iterator it = v.begin(); it < v.end();){
			int tmp = 100000;
			int i;
			for(i = 0; i < m; i++){
				if(*it <= tmp) tmp = *it;
				ans += *it;
				it++;
//				if(it == v.end()) break;
			}
			if(i == m){
				ans -= tmp;
			}
		}
		cout << ans << endl;
		ans = 0;
	}


}

C++: #include <iostream>
#include <queue>

int main(){
	int m,n;
	
	while(std::cin >> n >> m){
		//n,mがゼロで終了
		if(n == 0 && m == 0){
			break;
		}
		
		int sum_cost = 0;
		std::priority_queue<int> vegetable;
		for(int i = 0; i < n; ++i){
			int cost;
			std::cin >> cost;
			vegetable.push(cost);
		}
		
		for(int i = 1; i <= n; ++i){
			if(i % m){
				sum_cost += vegetable.top();
				vegetable.pop();
			}
			else
				vegetable.pop();
		}
		
		std::cout << sum_cost << std::endl;
	}
	
	return 0;
}

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


int main(){
	std::vector<int> vegetable; //dataset
	int n; //number of purchase
	int m; //capacity of bag

	while(std::cin >> n >> m){ //input dataset
		if(n == 0 && m == 0) //end of input
			break;

		std::vector<int> price; //price of vegetable
		for(int i = 0; i < n; ++i){ //input price
			int data;
			std::cin >> data;
			price.push_back(data);
		}

		
		std::sort(price.begin(), price.end(), std::greater<int>()); //sort price in descending order


		for(int i = 0; i < n; ++i){
			vegetable.push_back(price[i]);
		}

		int ans = 0; //minimum cost
		int count = 1; //counter
		while(!vegetable.empty()){
			if(count % m == 0){ //cheapst vegetable
				vegetable.erase(vegetable.begin());
				++count;
			} else if(count % m != 0){ //not cheapst vegetable
				ans += (int)vegetable.front();
				vegetable.erase(vegetable.begin());
				++count;
			}
		}
		std::cout << ans << std::endl; //output answer
		
	}


	return 0;
}

C++: #include<cstdio>
#include<iostream>
#include<algorithm>
#include<vector>
using namespace std;
int main(){
    int m,n;
    while(cin>>n>>m,n){
        int plz[1050]={0},total=0,cnt=1;
        for(int i=0;i<n;i++){
            cin>>plz[i];
        }
        sort(plz,plz+n);
        reverse(plz,plz+n);
        for(int i=0;i<n;i++){
            if(cnt!=m){
                total+=plz[i];
                cnt++;
            }
            else if(cnt==m){
                    cnt=1;
            }
        }
        cout<<total;
    }
    return 0;
}

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

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

int main(){

	int n,m; //問題文のn,m

	while(std::cin >> n >> m){
		if(n==0&&m==0) break;
		std::vector<int> p; //野菜価格一覧
		for(int i=0;i<n;i++){
			std::cin >> p[i];
		}
		sort(p.begin(), p.end());
		reverse(p.begin(), p.end()); //降順ソート
		
		for(int i=m-1;i<n;i+=m){
			p.erase(p.bigin() +i);
		}

		std::cout << accumulate(p.begin(), p.end(), 0) << std::endl;
	}

	return 0;
}

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

C++: #include <cstdio>
#include <algorithm>
using namespace std;
static const int MAX_N = 1001;
int vegs[MAX_N];

int main()
{
    int n, m, sum;
    for (; ; ) {
        scanf("%d %d", &n, &m);
        if (n == 0 && m == 0) break;
        sum = 0;
        for (int i = 0; i < n; i++) scanf("%d", &vegs[i]);
        sort(vegs, vegs+n, greater<int>());
        for (int i = 0; i < n; i++) {
            if (i % m == m - 1) continue;
            sum+= vegs[i];
        }
        printf("%d\n", sum);
    }
    return 0;
}

C++: #include <bits/stdc++.h>
using namespace std;

int main(){
  int n,m;
  while(1){
  cin>>n>>m;
  if(!n&&!m)break;
  priority_queue <int> Q;
  for(int i=0,a;i<n;i++)cin>>a,Q.push(a);

  int ans=0,cnt=0,sum=0;
  while(!Q.empty()){
    int t=Q.top();Q.pop();
    cnt++;
    sum+=t;
    if(n&&cnt==m) ans+=sum-t,sum=cnt=0,n--;
  }
  ans+=sum;
  cout <<ans<<endl;
  }
  return 0;
}

C++: #include <iostream>
#include <complex>
#include <sstream>
#include <string>
#include <algorithm>
#include <deque>
#include <list>
#include <map>
#include <numeric>
#include <queue>
#include <vector>
#include <set>
#include <limits>
#include <cstdio>
#include <cctype>
#include <cmath>
#include <cstring>
#include <cstdlib>
#include <ctime>
using namespace std;
#define REP(i, j) for(int i = 0; i < (int)(j); ++i)
#define FOR(i, j, k) for(int i = (int)(j); i < (int)(k); ++i)
#define SORT(v) sort((v).begin(), (v).end())
#define REVERSE(v) reverse((v).begin(), (v).end())
typedef complex<double> P;

int main() {
  int N, M;
  while(cin >>N >>M && N && M){
    int sum = 0;
    vector<int> v(N); REP(i, N) { cin >>v[i]; sum += v[i]; }
    SORT(v);
    REVERSE(v);
    for(int i = M - 1; i < N; i += M) sum -= v[i];
    cout <<sum <<endl;
  }
  return 0;
}

C++: #include <iostream>
#include <algorithm>
#include <vector>
#include <cstdio>
#include <string>
#include <cmath>
#include <cfloat>
#include <map>
using namespace std;
int main(){

	int n,m;
	while(cin>>n>>m,n!=0||m!=0){
		vector<int> a(n);
		for(int i=0;i<n;i++)
			cin>>a[i];
		sort(a.begin(),a.end());
		int s=0;
		int k=1;
		for(int i=n-1;i>=0;i--){
			if(k!=m){
				s+=a[i];
				k++;
			}
			else
				k=1;
		}
		cout<<s<<endl;
	}
	
}