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

C++: #include <cstdio>
#include <cstdlib>
#include <cmath>
#include <cstring>
#include <map>
#include <utility>
#include <set>
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <sstream>
#include <complex>
#include <stack>
#include <queue>

using namespace std;
typedef long long LL;
typedef pair<int, int> PII;
typedef complex<double> P;
static const double EPS = 1e-8;
static const int INF = (int)1e8;

#define FOR(i,k,n) for (int i=(k); i<(int)(n); ++i)
#define REP(i,n) for (int i=0; i<(int)(n); ++i)
#define FOREQ(i,k,n) for (int i=(k); i<=(int)(n); ++i)
#define FORIT(i,c) for(__typeof((c).begin())i=(c).begin();i!=(c).end();++i)
#define FIND(m,w) ((m).find(w)!=(m).end())

int main(void){
  int n,m;
  while(cin>>n>>m,n){
    vector<int> yen(n);
    REP(i,n)cin>>yen[i];
    sort(yen.begin(),yen.end());
    reverse(yen.begin(),yen.end());
    int ans = 0;
    REP(i,n)if((i+1)%m!=0)ans+=yen[i];
    cout<<ans<<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 <iostream>
using namespace std;

#define REP(i,b,n) for(int i=b;i<n;i++)
#define rep(i,n) REP(i,0,n)

int n, m, p[1001];

void solve() {
  rep(i,n) cin>>p[i];
  
  int rest = n, res = 0;
  while (rest >= m) {
    rep(z,m-1) {
      int l, most = 0;
      rep(i,n) if (most < p[i]) {
        l = i; most = p[i];
      }
      res += p[l]; p[l] = -1; rest--;
    }
    int l, most = 0;
    rep(i,n) if (most < p[i]) {
      l = i; most = p[i];
    }
    p[l] = -1; rest--;
  }
  
  rep(i,n) if (p[i] != -1) {
    res += p[i];
  }
  cout<<res<<endl;
}

int main (int argc, char const* argv[]) {
  while (cin>>n>>m, n||m) {
    solve();
  }
  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>());
		for(int i=0; i<n; i++){
			if((i+1)%m == 0 && (i+1) >= m && m != 1)
				i++;
			if(i != n)
				ans += v[i];
		}
		std::cout << ans << std::endl;
		delete[] v;
		ans = 0;
	}
}

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

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

void swap(int *s, int *t){
    int tmp;
    tmp = *s;
    *s = *t;
    *t = tmp;
}

int main(){
    int n,m,x;
    int flag = 0;
    int num = 0;
    std::vector<int> v;
    
    std::cin >> n >> m;
    
    while(std::cin >> x){
        v.emplace_back(x);
    }
    
    //std::sort(v.rbegin(),v.rend());
    
    for(int i = 0;i < v.size();i++){
        for(int j = i+1;j < v.size();j++){
            if(v[i] < v[j]){
                swap(&v[i],&v[j]);
            }
        }
    }
    
    for(int y = 0;y < n;y++){
        flag++;
        if(flag != m){
            num += v[y];
        }
        else
             flag = 0;
    }
    std::cout << num << std::endl;
}

C++: #include <bits/stdc++.h>
using namespace std;
#define all(c) (c).begin(),(c).end()
#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--)
#define REP(i,m,n) for(int i=(int)(m); i<(int)(n); i++)
#define iter(c) __typeof((c).begin())
#define tr(it,c) for(iter(c) it=(c).begin(); it!=(c).end(); it++)
#define pb(a) push_back(a)
#define pr(a) cout << (a) << endl
#define PR(a,b) cout << (a) << " " << (b) << endl
#define F first
#define S second
typedef long long ll;
typedef pair<int,int> P;
const int MAX=1000000001;
const ll MAXL=1000000000000000001LL;
const ll mod=1000000007;
int dx[4]={-1,0,1,0},dy[4]={0,-1,0,1};

int main() {
  int n,m;
  while(cin >> n >> m && (n||m)) {
    vector<int> a(n);
    rep(i,n) {
      int x;
      cin >> x;
      a[i]=x;
    }
    sort(all(a),greater<int>());
    int ans=0;
    rep(i,n) {
      if((i+1)%m) ans+=a[i];
    }
    pr(ans);
  }
  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
	int ans=0; //minimum cost

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

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


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

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


	return 0;
}

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

int main(){
    while (true) {
        int n;  // I will buy n vegetables.
        int m;  // One bag contains m vegetables.

        std::cin >> n >> m;
        if ( n==0 && m==0 ) {
            return 0;
        }

        // input vegetable's cost.
        std::priority_queue<int> buy;	            // the first item in 'buy' is the most expensive.
        int in;
        for (int i=0; i < n ; ++i) {
            std::cin >> in;
            buy.push(in);
        }

        int cost = 0;  // How much must I pay?
        int x = 1;  // This is the 'x'th vegetable in the bag.
        while ( ! buy.empty() ) {
            // the 'm'th item in the bag is free!
            if ( x > m-1 ) {
                x = 1;
            }else{
                cost += buy.top();
                ++x;
            }
            buy.pop();
        }

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

    return 0;
}