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>
using namespace std;
int main(){
  int n,m,ans,a,nk,count;
  while(cin>>n>>m){
    if(n==0&&m==0) break;
    int p[n];
    nk = n;
    count = 0;
    for(int i=0;i<n;i++) cin >> p[i];
    sort(p,p+n,greater<int>());
    ans = 0;
    a = 0;
    while(nk>=m){
      for(int i=a;i<(a+m)-1;i++) ans += p[i];
      a += m;
      nk -= m;
      count += m;
    }
    if(n>count){
      for(int i=count;i<n;i++) ans += p[i];
    }     
    cout << ans << endl;
  }
  return 0;
}

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

int main(){
  int n, m;
  while(cin >> n >> m, n, m){
    int pn[1000];
    for(int i = 0; i < n; i++) cin >> pn[i];
    sort(pn, pn+n);
    int nowm = 0, ans = 0;
    for(int i = n-1; i >= 0; i--){
      nowm++;
      if(nowm == m) nowm = 0;
      else{
	ans += pn[i];
      }
    }
    cout << ans << endl;
  }
}

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

using namespace std;

int main(){
	
	int n, m;
	
	while(true){
		
		cin >> n >> m;
		
		if(n == 0 && m == 0){
			break;
		}
		
		int p[200000];
		
		long long int sum = 0;
		
		for(int i = 0; i < n; i++){
			cin >> p[i];
			sum += p[i];
		}
		
		sort(p, p + n);
		
		for(int i = n - m; i >= 0; i -= m){
			sum -= p[i];
		}
		
		cout << sum << endl;
		
	}
	
	return 0;
}

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


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

using namespace std;

int main()
{
  int n, m, ans, p[1000];
  while(1)
  {
    ans = 0;

    cin >> n >> m;
    if(m == n && !m)
      break;

    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 + 1) % m)
	ans += p[i];
    }

    cout << ans << endl;
  }
  return 0;
}

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

int main(){
    int n, m, p, sum;
    std::vector<int> price_list = {};

    while(std::cin >> n >> m && (n != 0 || m != 0)){
        sum = 0;
        for(int i = 0;i < n;i++){
            std::cin >> p;
            price_list.push_back(p);
            sum += p;
        }
        std::sort(price_list.begin(), price_list.end(), std::greater<int>());
        for(int i = 1;i <= n/m;i++){
            sum -= price_list.at(i * m - 1);
        }
        std::cout << sum << std::endl;
    }
}

C++: #include <cstdio>
#include <algorithm>
using namespace std;
bool comp(const int& a, const int& b) {
    return a>b;
}
int n, m;
int p[1000];
int main() {
    while (scanf("%d%d",&n,&m)) {
        if (!n&&!m) break;
        for (int i=0; i<n; i++) {
            scanf("%d",&p[i]);
        }
        sort(p,p+n,comp);
        for (int i=m-1; i<n; i+=m) {
            p[i]=0;
        }
        int res=0;
        for (int i=0; i<n; i++) {
            res+=p[i];
        }
        printf("%d\n",res);
    }
}

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

int main(){
	int m,n;
	
	while(std::cin >> n >> m){
		//n,mがゼロで終了
		if((n = 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<stdio.h>
int  main(){

int N,M;
int n[1001]={};

while(1)
{
int s=0;
scanf("%d %d",&N,&M);
if(N==0&&M==0)break;

for(int i=1;i<=N;i++)
scanf("%d",&n[i]);

for(int i=1;i<=N;i++)
for(int j=N;j>i;j--)
if(n[j]>n[j-1]){int t=n[j-1];n[j-1]=n[j];n[j]=t;}

for(int i=1;i<=N;i++)
{if(i%M!=0)s+=n[i];}

printf("%d\n",s);
}

return 0;
}

C++: #include <bits/stdc++.h>
#define FOR(v, s, t) for(int v = s; v < t; ++v)
using namespace std;

int main(){
	int n, m, min;
	vector< int > p;
	
	while(cin >> n >> m, n){
		p.resize(n);
		FOR(i, 0, n) cin >> p[i];
		
		sort(p.begin(), p.end());
		reverse(p.begin(), p.end());
		
		min = 0;
		FOR(i, 0, n){
			if((i + 1) % m != 0){
				min += p[i];
			}
		}
		
		cout << min << endl;
	}
	
	return 0;
}

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

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 <algorithm>
#include <functional>
using namespace std;

int main(){
  int n,m,fig[1001];
  while(cin >> n >> m){
    int ans = 0;
    for(int i=0;i<n;i++) cin >> fig[i];
    sort(fig,fig+n,greater<int>());
    for(int i=0;i<n;i++){
      if((i+1) % m) ans += fig[i];
    }
    for(int i=n-1,j=0;j<n%m;i--,j++) ans += fig[i];
    fill(fig,fig+1001,0);
    cout << ans << endl;
  }
}

C++: #include<iostream>

using namespace std;

int main()
{
	int n,m,i,j,p[1000];
	
	for(;;)
	{
		cin >> n >> m;
		if(n==0)
			break;
		
		int ans=0;
		
		for(i=0;i<n;i++)
		{
			cin >> p[i];
		}
		for(i=0;i<n;i++)
		{
			for(j=i+1;j<n;j++)
			{
				if(p[i]<p[j])
				{
					int a;
					a=p[i];
					p[i]=p[j];
					p[j]=a;
				}
			}
		}
		for(i=0;i<n;i++)
		{
			if((i+1)%m!=0)
				ans+=p[i];
		}
		cout << ans << endl;
	}
}

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

int main() {
	int a,b,i,sum=0;
	int c[10000];
	while(1){
		cin >> a >> b;
		if(a==0 && b==0) break;
		for(i=0;i<a;i++){
			cin >> c[i];
			sum+=c[i];
		}
		sort(c,c+a);
		reverse(c,c+a);
		for(i=b-1;i<a;i+=b){
			sum-=c[i];
		}
		cout << sum << endl;
		sum=0;
	}
	

	return 0;
}

C++: 
#include"iostream"
using namespace std;
int main() {
	while (1) {
		int n, m,p[10000],sum=0;
		cin >> n >> m;
		
		if (n == 0 && m == 0)break;

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

		for (int j = 0; j < n - 1; j++) {
			for (int i = 1; i < n ; i++) {
				if (p[i] < p[i + 1]) {
					swap(p[i], p[i + 1]);

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

			}
		
		cout << sum << endl;
	}
		
	return 0;
}

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

int main(){
    int N,M;
    while(cin >> N >> M, N != 0){
        vector<int> p(N);
        for(int i = 0; i < N; i++) cin >> p[i];
        sort(p.rbegin(), p.rend());

        int ans = 0;
        for(int i = 0; i < N; i++){
            if((i+1) % M) ans += p[i]; 
        }
        cout << ans << endl;
    }
}