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 <cstdio>
#include <algorithm>

using namespace std;

int main(void)
{
	int i, n, m, p;
	int sum, array[1000];
	
	while (1){		
		scanf("%d %d", &n, &m);
		
		if (!n && !m){
			break;
		}
		
		for (i = 0; i < n; i++){
			scanf("%d", &array[i]);
		}
		
		sort(array, array + n);
		reverse(array, array + n);
		
		for (i = 0, sum = 0; i < n; i++){
			if ((i + 1) % m != 0 || n - i + 1 < m){
				sum += array[i];
			}
		}
		
		printf("%d\n", sum);
	}
	
	return (0);
}

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];
}
sort(be,be+n,greater<int > );
while(n>=m){
x+=m;
ans-=be[x];
n-=m;
}
cout<<ans<<endl;
}
}

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(n); //野菜価格一覧
		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 <iostream>
#include <vector>
#include <algorithm>

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

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

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

		//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 <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<iostream>
#include<algorithm>
using namespace std;
int main(){
  int n,m;
  int p[11111];
  int sum;
  while(1){
    cin>>n>>m;
    sum=0;
    if(n+m==0) break;
    for(int i=0;i<n;i++){
      cin>>p[i];
    }
    sort(p,p+n,greater<int>());
    for(int i=0;i<n;i++){
      sum=sum+p[i];
      if((i+1)%m==0){
	sum=sum-p[i];
      }
    }
    
    cout<<sum<<endl;
  }
}

C++: #include<iostream>
#include<string>
#include<algorithm>
#include<map>
#include<set>
#include<utility>
#include<vector>
#include<cmath>
#include<cstring>
#include<cstdio>
#include<time.h>
#define loop(i,a,b) for(int i=a;i<b;i++) 
#define rep(i,a) loop(i,0,a)
#define pb push_back
#define mp make_pair
#define all(in) in.begin(),in.end()
const double PI=acos(-1);
const double EPS=1e-10;
using namespace std;
typedef long long ll;
typedef vector<int> vi;
int main(){
	int a,b;
	while(cin>>a>>b,a||b){
		vector<int>in(a);
		rep(i,a)cin>>in[i];
		sort(all(in));
		int sum=0;
		int co=0;
		for(int i=a-1;i>=0;i--){
			co++;
			if(co==b){
				co=0;
				continue;
			}
			sum+=in[i];
		}
		cout<<sum<<endl;
	}
}

C++: #include <iostream>
#include <vector>
#include <algorithm>
#include <string>
#include <cstring>
#include <cstdio>
#include <cmath>
#include <queue>
#include <stack>
#include <map>
#include <set>
#include <bitset>
 
#define rep(i, n) for(int i = 0; i < (n); i++)
#define FOR(i, a, b) for(int i = (a); i < (b); i++)
#define all(v) (v).begin(), (v).end()
#define rev(s) (s).rbegin(), (s).rend()
#define MP make_pair
#define X first
#define Y second
 
using namespace std;
 
typedef long long ll;
typedef pair<int, int> P;

int main(){
	int n, m;
	while(cin >> n >> m, n|m){
		vector<int> v(n);
		rep(i, n) cin >> v[i];
		sort(rev(v));
		int sum = 0;
		rep(i, n){
			if((i+1)%m) sum += v[i];
		}
		cout << sum << endl;
	}
	return 0;
}

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

int main() {
  int n, m;
  int data[1000];
  int sum;


  while(1) {
    cin >> n >> m;
    if(n == 0 && m == 0) break;
    for(int i = 0; i < n; i++) {
      cin >> data[i];
    }
    sort(data, data+n);
    sum = 0;
    int i = n-1;
    while(1) {
      for(int j = 0; j < m; j++) {
	if(i < 0) {
	  break;
	}
	if(j+1 == m) {
	} else {
	  sum += data[i];
	}
	i--;
      }
      if(i < 0) break;
    }
    cout << sum << endl;
  }
  return 0;
}

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

using namespace std;

int main() {

	int n, m, t, j=0, x;
	deque<int> p;

	while(cin >> n >> m) {
		if(n==0&&m==0)
			break;
		t=0;
		p.clear();
		for(int i=0; i<n; i++) {
			cin >> x;
			p.push_back(x);
		}
		sort(p.begin(), p.end(), 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>

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

int main(void)
{
	int n, m;
	
	while (scanf("%d %d", &n, &m)){
		if (n == 0 && m == 0) break;
		
		vector <int> v;
		int tmp;
		for (int i = 0; i < n; i++){
			scanf("%d", &tmp);
			v.push_back(tmp);
		}
		sort(v.begin(), v.end(), greater<int>());
		
		int res = 0;
		int sum = 0;
		for (int i = 0; i < n; i++){
			if ((i + 1) % m == 0) {
				sum += v[i];
			}
			res += v[i];
		}
		
		printf("%d\n", res - sum);
	}
	
	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 <bits/stdc++.h>
using namespace std;

int p[1010];

int main(){
	while(1){
		int n,m,t=0;
		cin>>n>>m;
		if(n==0&&m==0) break;
		for(int i=0;i<n;i++) cin>>p[i];
		int f=1;
		while(f==1){
			f=0;
			for(int j=0;j<n-1;j++){
				if(p[j]<p[j+1]){
					swap(p[j],p[j+1]);
					f=1;
				}
			}
		}
		for(int i=1;i<=n/m;i++){
			p[i*m-1]=0;
		}
		for(int i=0;i<n;i++){
			t+=p[i];
		}
		cout<<t<<endl;
	}
	return 0;
}