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> 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){
				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 <algorithm>

#define MAX_NM 1000

int n, m, ans;
int p[MAX_NM];

void solve();

int main(){
    while(true){
        std::cin >> n >> m;
        if(n == 0 && m == 0)
            break;
        for(int i = 0; i < n; ++i)
            std::cin >> p[i];
        solve();
        std::cout << ans << std::endl;
    }
    return 0;
}

void solve(){
    ans = 0;
    std::sort(p, p + n, std::greater<int>());
    for(int i = 1; i <= n; ++i){
        if(i % m == 0)
            continue;
        ans += p[i - 1];
    }
    return;
}

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

const float PI = 3.1415926;
const int N = 100000;

using namespace std;

typedef long long ll;
typedef long double ld;

int main() {
  int n,m,q;
  ll res;
  while(true) {
    cin >> n >> m;
    if(n == 0) break;
    vector<int> v;
    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+=m) {
      for(int j = i; j < m + i - 1; j++) {
        res += v[j];
      }
    }
    cout << res << endl;
  }
  
  return 0;
}

C++: #include <iostream>
#include <queue>
 
int main(){
    std::priority_queue<u_int> prices;
    u_int num_of_item, size_of_bag, price;
    
    while(1){
        std::cin >> num_of_item >> size_of_bag;
        if(num_of_item == 0 && size_of_bag == 0)
            break;
            
        for(u_int i = 0; i < num_of_item; ++i){
            std::cin >> price;
            prices.push(price);
        }
        
        u_int sum = 0;
        while(!prices.empty()){
            for(u_int i = 0; i < size_of_bag; ++i){
                if(i != size_of_bag - 1){
                    sum += prices.top();
                }
                prices.pop();
                if(prices.empty()){
                    break;
                }
            }
        }
        std::cout << sum << std::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.begin() +i);
		}

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

	return 0;
}

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

C++: #include<bits/stdc++.h>
#define range(i,a,b) for(int i = (a); i < (b); i++)
#define rep(i,b) range(i,0,b)
#define itrep(it, a) for(it = (a).begin(); it != (a).end(); it++)
#define all(a) (a).begin(), (a).end()
#define debug(x) cout << "debug " << x << endl;
#define INF (1 << 30)
using namespace std;

int main(){
    int n,m;
    while(cin >> n >> m, n||m){
        int a[1005], ans = 0;
        rep(i,n) cin >> a[i];
        sort(a, a + n, greater<int>());
        rep(i,n){
            if(i % m != m - 1) ans+=a[i];
        }
        cout << ans << endl;
    }
}

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

C++: #include<iostream>
#include<algorithm>
using namespace std;
main(){
int ans=0;
int be[10002];
int x=-1,n,m;
while(1){
x=-1;
ans=0;
cin>>n>>m;
if(n==m==0)break;
for(int i=0;i<n;i++){
cin>>be[i];
ans+=be[i];
}
x=m%n;
n-=x;
while(n>=m){
ans-=be[n];
n-=m;
}
cout<<ans<<endl;
}
}

C++: #include <iostream>
#include <queue>
  
int main(){
    std::priority_queue<u_int>  vegetable;
    u_int n, m, price;
     
    while(1){
        std::cin >> n >> m;
        if(n == 0 && m == 0)
            break;
             
        for(u_int i = 0; i < n; ++i){
            std::cin >> price;
            vegetable.push(price);
        }
         
        u_int sum = 0;
        for(u_int i = 1; i <= n; ++i){
            if(i % m != 0){
                sum += vegetable.top();
            }
            vegetable.pop();
        }
        std::cout << sum << std::endl;
    }
  
    return 0;
}

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