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

#define MAX_NM 1000

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

void solve();

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

void solve(){
    std::sort(p, p + n, std::greater<int>());
    for(int i = 1; i <= n; ++i)
        all -= p[i * m - 1];
    return;
}

C++: #include<iostream>
#include<algorithm>
using namespace std;
int main()
{
    int n,m,sum;
    int p[1010];
    
    while(cin >> n >> m,n!=0&&m!=0){
        for(int i=0;i<n;i++){
            cin >> p[i];
        }
        sort(p,p+n);
        reverse(p,p+n);
        sum = 0;
        for(int i=0;i<n;i++){
            if( (i+1)%m != 0) sum += p[i];
        }
        cout << sum << endl;
    }
    return 0;
}

C++: #include<iostream>
#include<algorithm>
using namespace std;
int n,m,a[1000];
main()
{
	while(cin>>n>>m,n)
	{
		int ans=0;
		for(int i=0;i<n;i++)
		{
			cin>>a[i];
			ans+=a[i];
		}
		sort(a,a+n);
		for(int i=n-m;i>=0;i-=m)
		{
			ans-=a[i];
		}
		cout<<ans<<endl;
	}
}

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

int main(){
	int n,m;
	while(std::cin >> n >> m){
		if(n == 0 && m == 0){
			break;
		}
		std::priority_queue<int> que;
		int vegetable;
		for(int i = 0; i < n; ++i){
			std::cin >> vagetable;
			que.push();
		}
		int price = 0;
		for(int i = 0; i < n; ++i){
		    if((i % m) != (m - 1)){
	  	        price += que.top();
		        que.pop();
		    }
		}
		std::cout << price << std::endl;
	}
	return 0;
}

C++: #include<stdio.h>
#include<stdlib.h>
#include<iostream>
#include<string>
#include<vector>
#include<math.h>
#include<queue>
#include <algorithm>
#include<functional>


#define CI cin >>
#define CO cout <<
#define E << endl;
#define F(i,max) (for(int i = 0;i < max;++i))

using namespace std;

int n = 0;
int m = 0;

int total = 0;

vector<int> price;

void input() {
	CI n >> m;
	
	price.resize(n);

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

}

int GetPrice() {
	int amari = 0;

	total = 0;

	sort(price.begin(), price.end(), greater<int>());
	amari = n % m;
	for (int i = 0; i < n - amari; i++) {
		if ((i + 1) % m != 0) {
			total += price[i];
		}
	}
	if (amari != 0) {
		for (int i = n - amari; i < n; ++i) {
			total += price[i];
		}
		
	}
	return 0;
}

int main(void) {
	
	while (true) {
		input();
		if (n == 0 && m == 0) {
			break;
		}

		GetPrice();

		CO total;
	}
	return 0;
}

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

int main(){
	int n,m,v,ans;
	while(1){
		vector<int>  b ;
		ans=0;
		cin >> n >> m ;
		if( (n==0) && (m==0) ){
			return 0;
		}
		for(int i=0;i<n;i++){
			cin >> v;
			ans += v;
			b.push_back(v);
		}
		sort(b.begin(),b.end());
		reverse(b.begin(),b.end());
		for(int i=m-1;i<n;i+=m){
			ans -= b[i];
		}
		cout << ans << "\n";
	}
}

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

using namespace std;

int main() {

	int n, m, t, j=0;
	int p[1001];

	while(cin >> n >> m) {
		if(n==0&&m==0)
			break;
		t=0;
		for(int i=0; i<n; i++) {
			cin >> p[i];
		}
		sort(p, p+n, greater<int>());
		for(int i=0; i<n; i++) {
			t+=p[i];
			j++;
			if(j==m) {
				t-=p[i];
				j=0;
			}
		}
		cout << t << endl;
	}

	return 0;

}

C++: #include<iostream>
#include<cstdio>
#include<string>
#include<map>
#include<algorithm>
#include<queue>
#include <functional>
using namespace std;

int main(){
  
  int n,m,ans=0;
  int p[10000];
  
  while(1){
    ans=0;
    cin >> n >> m;
    if(n==0 && m==0)break;
    for(int i=0;i<n;i++){
      cin >> p[i];
    }
    sort(p,p+n,greater<int>());
    
    if(n < m){
      for(int i=0;i<n;i++){
	ans+=p[i];
      }
      cout << ans << endl;
    }
    else{
      for(int i=1;i<n+1;i++){
	if(i % m == 0){
	  ans+=0;
	}
	else{
	  ans+=p[i-1];
	}
      }
      cout << ans << endl;
    }
  }
  return 0;
}

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

int main(){
  int n,m;
  while(cin>>n>>m,n){
    int veg[n];
    for(int i=0;i<n;i++)cin>>veg[i];
    sort(veg,veg+n);
    int res=0;
    for(int i=0;i<n;i++){
      if(i%n==0)continue;
      res+=veg[i];
    }
    cout << res << 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>
#include <algorithm>
#include <vector>
#include <string>
#include <stack>
#include <queue>
#include <cctype>
#include <cstring>
#define rep(i, m, n) for (int i = m; i < n; i++)
#define repr(i, n) for (int i = n; i >= 0; i--)
#define ll long long
#define ull unsigned long long
#define push(a) push_back(a)
#define pop(a) pop_back(a)
#define debug(x) cout << #x << ": " << x << endl
#define SORT(v, n) sort(v, v + n);
#define VSORT(v) sort(v.begin(), v.end());
#define INF 999999999
using namespace std;
typedef pair<int, int> P;
typedef pair<ll, ll> LP;
typedef pair<int, P> PP;
typedef pair<ll, LP> LPP;

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

ll n,m;
ll p[100005]={};
ll ans=0;

int main()
{
    while(1){
        cin >> n >> m;
        if(n==0&&m==0)return 0;
    
        for (int i = 0; i < n; i++) {
            cin >> p[i];
        }

        sort(p,p+n);
        reverse(p,p+n);

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

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

using namespace std;

int main() {
    ios::sync_with_stdio(false);

    int n, m;
    while (1) {
        cin >> n >> m;
        if (n == 0 && m == 0) break;
        vector<int> p(n);
        for (int i=0; i<n; ++i) {
            cin >> p[i];
        }
        sort(p.begin(), p.end(), greater<int>());

        int sum = 0, minus = 0;
        for (int i=0; i<(int)p.size(); ++i) {
            sum += p[i];
            if ((i + 1) % m == 0) minus += p[i];
        }
        cout << sum - minus << endl;
    }
    return 0;
}

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

int main(void) {
    u_int m, n;

    std::cin >> n >> m;
    for (; m != 0 && n != 0; std::cin >> n >> m) {
        std::priority_queue<u_int> p;
        for (u_int i = 0, tmp; i < n; ++i) {
            std::cin >> tmp;
            p.push(tmp);
        }

        u_int sum = 0;
        for (u_int i = 1; i <= n; ++i) {
            if (i % m) {
                sum += p.top();
                p.pop();
            } else {
                if (!p.empty()) p.pop();
            }
        }

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

    return 0;
}