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>

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;
	}
}

C++: #include <iostream>
#include <algorithm>
#include <queue>
#include <vector>
#include <functional>
#include<cstdio>  

using namespace std;

int main(void){
	int n,m;
	int a;
	while(1){
		cin >> n >> m;
		if(n==0 && m==0)break;
		int ans=0;
		priority_queue<int,vector<int>,greater<int> > num;
		for(a=0;a<n;a++){
			int nn;
			scanf("%d",&nn);
			num.push(nn);
		}
		for(a=1;a<=n;a++){
			if(a%m==0)ans+=num.top();
			num.pop();
		}
		cout << ans << endl;
	}
	return 0;
}

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;
			for(int i = 0; i < m; i++){
				if(*it <= tmp) tmp = *it;
				ans += *it;
				it++;
//				if(it == v.end()) break;
				if(i == m - 1){
					ans -= tmp;
				}
			}
		}
		cout << ans << endl;
		ans = 0;
	}


}

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

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

using namespace std;

void solve()
{
	int m, n;
	while(cin >> m >> n)
	{
		if(!m && !n)
		{
			break;
		}
		priority_queue<int, vector<int> > PQue;
		for(int i = 0; i < m; ++i)
		{
			int price;
			cin >> price;
			PQue.push(price);
		}
		int sum = 0;
		while(true)
		{
			for(int i = 0; i < n - 1; ++i)
			{
				if(PQue.empty())
				{
					break;
				}
				sum += PQue.top();
				PQue.pop();
			}
			if(PQue.empty())
			{
				break;
			}
			PQue.pop();
		}
		cout << sum << endl;
	}
}

int main()
{
	solve();
	return(0);
}

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

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

int main(){

	int num, limit;

	while(std::cin >> num >> limit){
		std::vector<int> price;
		int sum_price = 0;
		//input
		for(int i = 0; i < num; ++i){
			int buf;
			sum_price += buf;
			std::cin >> buf;
			price.push_back(buf);
		}
		//sort
		std::sort(price.begin(),price.end(),std::greater<int>());
		//discount
		int discount = 0;
		int in_bag = 0;
		for(auto itr = price.begin(); itr != price.end(); ++itr){
			++in_bag;
			if(in_bag == limit){
				discount += itr;
				in_bag = 0;
			}
		}

		std::cout << sum_price - discount << std::endl;
	}
	return 0;
}

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

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

int main(){
	int vnum, capacity, total = 0;
	std::vector<int> vprice;

	while(std::cin >> vnum >> capacity){
		//end
		if(vnum == 0 && capacity == 0) break;

		int tmp,buf = capacity;
		std::vector<int> vprice;

		//input
		for(int i = 0; i < vnum; ++i){
			std::cin >> tmp;
			vprice.push_back(tmp);
	}

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

		//sum price
		std::for_each(vprice.begin(),vprice.end(), 
			[&total,buf,&capacity](int x) { capacity != 1 ? (total += x, --capacity) : capacity = buf; } );

		//output
		std::cout << total << std::endl;
	}

	return 0;
}

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

int main(){

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

	while(std::cin >> n >> m){
		if(n==0&&m==0) break;
		std::array<u_int, n> p; //野菜価格一覧
		for(int i=0;i<n;i++){
			std::cin >> p[i];
		}
		std::sort(p.begin(), p.end());
		
		int price=0; //最終出力

		while(n>=m){
			for(int i=0;i<m;i++){
				price += p[n-1-i];
			}
			n -= m;
		}
		for(int i=0;i<n;i++){
			price += p[i];
		}

		std::cout << price << std::endl;
	}

	return 0;
}

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 <bits/stdc++.h>
#define rep(i,l,n) for(int i=l;i<n;i++)
#define rer(i,l,n) for(int i=l;i<=n;i++)
#define all(a) a.begin(),a.end()
#define o(a) cout<<a<<endl
#define pb(a) push_back(a)
#define mk(a,b) make_pair(a,b)
#define fi first
#define se second
using namespace std;
typedef long long ll;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef pair<int,int> pii;

int main(){
	int n,m;
	while(1){
		int ans=0;
		cin>>n>>m;
		if(n==0 && m==0) break;
		vi d(n);
		rep(i,0,n){
			cin>>d[i]; ans+=d[i];
		}
		sort(all(d));
		reverse(all(d));
		rep(i,0,n){
			if((i+1)%m==0) ans-=d[i];
		}
		o(ans);
	}	
}

C++: #include <cstdio>
#include <stack>
#include <cstring>
#include <vector>
#include <algorithm>
#include <string>
#include <map>
#include <set>
#include <queue>
#include <climits>

using namespace std;

#define reep(i,f,t) for(int i=f ; i<int(t) ; ++i)
#define rep(i,n) reep(i, 0, n) 

typedef vector<int> vi;
typedef vector<vi> vvi;
typedef pair<int,int> pii;

int main()
{
	int n, m;
	while(scanf("%d%d", &n, &m), n){
		int a[1000];
		rep(i, n)
			scanf("%d", &a[i]);
		sort(a, a+n, greater<int>());
		int ans = 0;
		rep(i, n){
			if(i%m != m-1)
				ans += a[i];
		}
		printf("%d\n", ans);
	}
	return 0;
}