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

vector<int> l;
int n,m;

bool input(){
  cin>>n>>m;
  if(n==m&&n==0)return false;
  l.clear(),l.resize(n);
  for(int i=0;i<n;i++){
    cin>>l[i];
  }
  return true;
}

int solve(){
  sort(l.rbegin(),l.rend());
  int ans = 0;
  for(int i=0;i<n;i++){
    if( (i+1) %m == 0){
      continue;
    }
    ans += l[i];
  }
  return ans;
}

int main(){
  while(input()){
    cout<<solve()<<endl;
  }
}

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

using namespace std;

int main() {
    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<algorithm>
using namespace std;

int main() {
	int n, m;
	while (cin >> n >> m, n, m) {
		int p[1000];
		int sum = 0;

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

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

		for (int i = m - 1;i < n;i += m) {
			sum -= p[i];
		}
		cout << sum << endl;
	}
	return 0;
}

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

inline 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 <iostream>
#include <vector>
#include <algorithm>

int main(void){
    std::vector<int> price;
    int num_vegetable, bag_capacity, price_sum = 0;
    std::cin >> num_vegetable >> bag_capacity;
    for(int p, i = 0; i < num_vegetable; ++i){
        std::cin >> p;
        price.push_back(p);
    }
    
    std::sort(price.begin(), price.end(), std::greater<int>());
    
    for(int i = 0; i < num_vegetable; ++i){
        if((i + 1) % bag_capacity != 0)
            price_sum += price.at(i);
    }
    std::cout << price_sum << std::endl;
}

C++: #include<stdio.h>

int main(void)
{
	int a, b, c[1000], d, e, f, g = 1, i, j;
	while (scanf("%d %d", &a, &b))
	{
		if (a == 0 && b == 0)break;
		j = 0, g = 1;
		for (i = 1;i <= a;i++)
		{
			scanf("%d", &d);
			c[i] = d;
		}
		f = a;

		while (g)
		{
			for (i = 1;i <= a;i++)
			{
				if (c[i] < c[i + 1])
				{
					e = c[i];
					c[i] = c[i + 1];
					c[i + 1] = e;
				}
			}

			a--;
			if (a == 0)
			{
				g = a;
			}
		}
		for (i = 1;i <= f;i++)
		{
			if(i % b != 0)
			{
				j += c[i];
			}
		}

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

C++: #include<bits/stdc++.h>
using namespace std;
int main()
{
    int n,m;
    while(cin>>n>>m,n,m){
        int vege[1000];
        for(int i=0;i<n;i++)cin>>vege[i];
        sort(vege,vege+n);
        for(int i=1;n-m*i>=0;i++)vege[n-m*i]=0;
        for(int i=1;i<n;i++)vege[0]+=vege[i];
        cout<<vege[0]<<endl;
    }
}

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

int n,m,*b,ans;

int main(){
	while(true){
		cin >> n >> m;
		if(!n && !m)
			return 0;
		b = new int[n];
		ans = 0;
		for(int i=0; i<n; i++)
			cin >> b[i];
		sort(b,b+n,greater<int>());
		for(int i=1; i<=n; i++){
			if(i%m == 0)
				continue;
			ans += b[i-1];
		}
		cout << ans << endl;
	}
}

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

using namespace std;

int main(void){

  int n,m;
  while( cin >> n >> m , n && m ){

    int ve[1000];
    for( int i = 0 ; i < n ; i++ ){
      cin >> ve[i];    
    }

    sort( ve , ve + n );

    /*  for( int i = 0 ; i < n ; i++ ){
      cout << ve[i] << " ";
    }
    cout << endl;
    */

    int sum = 0;
    int cnt = 1;
    for( int i = n - 1 ; i >= 0 ; i-- ){
      if( cnt == m ){
	cnt = 0;
      }
      else sum += ve[i];
      cnt++;
    }
    
    cout << sum << endl;

  }
  return 0;
}

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

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

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

#define REP(i,n) for(int i=0;i<(int)n;++i)
#define FOR(i,c) for(__typeof((c).begin())i=(c).begin();i!=(c).end();++i)
#define ALL(c) (c).begin(), (c).end()
const int INF = 1<<29;

int main() {
  int n,m;
  while(cin >> n >> m, n+m) {
    vector<int> a(n);
    REP(i,n) {
      cin >> a[i];
    }
    sort(ALL(a), greater<int>());
    int res = 0;
    int i;
    for (i=0; i+m<=n; i+=m) {
      REP(j,m-1) {
        res += a[i+j];
        //    cout << a[i+j] << "" ; 
      }
      //cout << endl;
    }
    //  cout << i << endl;
    if (i < n) {
      REP(j, n-i) {
        res += a[i+j];
        //  cout << a[i+j] << endl;
      }
    }
    cout << res << 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-1;i+=m){
			p[i]=0;
		}
		std::cout << accumulate(p.begin(), p.end(), 0) << std::endl;
		
	}

	return 0;
}

C++: #include<iostream>
#include<string>
#include<vector>
#include<utility>
#include<queue>
#include<algorithm>
#include<cmath>
#include<cstdio>
#include<cstring>
#include<cstdlib>
#include<complex>
#define INF 2147483647
#define llINF 9223372036854775807
#define pb push_back
#define mp make_pair 
#define F first
#define S second
#define ll long long

using namespace std;
int main(){
  int n,m;
  while(cin>>n>>m,n+m){
    vector<int>ve(n);
    ll ans=0;
    for(int i=0;i<n;i++){
      cin>>ve[i];ans+=ve[i];
    }
    sort(ve.begin(),ve.end(),greater<int>());
    for(int i=m-1;i<n;i+=m)
      ans-=ve[i];
    cout<<ans<<endl;
  }
  return 0;
}

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

using namespace std;

int main()
{
	int n, m;
	int veg[1024];
	int sum;

	while (1){
		sum = 0;
		scanf("%d%d", &n, &m);

		if (n == 0 && m == 0){
			break;
		}

		for (int i = 0; i < n; i++){
			scanf("%d", &veg[i]);
		}

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

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

		cout << sum << endl;
	}

	return (0);
}