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> vegetables;
	int num,cap,price,i;

	while(std::cin >> num >> cap){

		if(num == 0 && cap == 0){
			break;
		}

		std::vector<int> vegetables;
		int sum = 0;

		for(i=0; i<num; ++i){
			std::cin >> price;
			vegetables.push_back(price);
		}

		sort(vegetables.begin(), vegetables.end(), std::greater<int>());

		i = 0;

		while(i < num){

			if((i+1) % cap != 0){
				sum += vegetables.at(i);
			}

			++i;
		}

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

		//vegetables.clear();
	}

}

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

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(std::v.bigin() +i);
		}

		std::cout << accumulate(p.begin(), p.end(), 0) << 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 <iostream>
#include <string>
#include <vector>
#include <algorithm>
using namespace std;

int main() {
	// your code goes here
	int m,p,tmp;
	while(cin >> m >> p && m!=0){
		vector<int> v;
		int sum=0;
		for(int i=0;i<m;i++){
			cin >> tmp;
			v.push_back(tmp);
		}
		sort(v.begin(),v.end());
		int mods=m%p;
		for(int i=0;i<mods;i++)
		sum+=v[i];
		for(int i=mods;i<v.size();i++){
			if((i-mods)%p==0);
			else
				sum+=v[i];
		}
		cout << sum << endl;
	}
	return 0;
}

C++: #include<iostream>
#include<iomanip>
#include<algorithm>
#include<array>
#include<bitset>
#include<cassert>
#include<cctype>
#include<cmath>
#include<cstdio>
#include<cstring>
#include<functional>
#include<limits>
#include<list>
#include<map>
#include<numeric>
#include<set>
#include<stack>
#include<string>
#include<sstream>
#include<unordered_map>
#include<queue>
#include<vector>
using namespace std;

//#define int long long
using ll = long long;
using ull = unsigned long long;
using pii = pair<int, int>;

#define rep(i,a,b) for(int i=(a);i<(b);i++)
#define rrep(i,a,b) for(int i=(b)-1;i>=(a);i--)
#define all(a) (a).begin(),(a).end()
#define dump(o) {cerr<<#o<<" "<<o<<endl;}
#define dumpc(o) {cerr<<#o; for(auto &e:(o))cerr<<" "<<e;cerr<<endl;}
#define INF 0x3f3f3f3f
#define INFL 0x3f3f3f3f3f3f3f3fLL
const int MOD = 1e9 + 7;

signed main() {
	int p[1010] = {};
	for (int n, m; cin >> n >> m&&n;) {
		memset(p, 0, sizeof(p));
		int ans = 0;
		rep(i, 0, n) { cin >> p[i]; ans += p[i]; }
		sort(p, p + n);
		for (int i = n%m; i < n; i += m) {
			ans -= p[i];
		}
		cout << ans << endl;
	}
	return 0;
}

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

int main(){
	int n, m;
	
	while(std::cin >> n >> m){
		if(n == 0 && m == 0){ break; }
		
		std::vector<int> price(n, 0);
		int sum_price = 0; //全ての値段の合計
		
		for(int i = 0 ; i < n ; ++i){
			std::cin >> price[i];
			sum_price += price[i];
		}
		
		std::sort(price.begin(), price.end(), std::greater<int>());
		
		for(int i = m - 1 ; i < n ; i += m){
			sum_price -= price[i];
		}
		std::cout << sum_price << std::endl;
	}
    return 0;
}

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

int main(){
while(1){
int sina[1000],n,m,sum=0;
scanf("%d%d",&n,&m);
if(n==0&&m==0)return 0;
for(int i=0;i<n;i++){
scanf("%d",&sina[i]);
sum+=sina[i];
}
sort(sina,sina+n);
for(int i=n-m;i>=0;i-=m){
sum-=sina[i];
}
printf("%d\n",sum);
}
}

C++: #include <bits/stdc++.h>

using namespace std;

int main()
{
  int n, m;
  while(cin >> n >> m, n || m){
    int p[1001];
    for(int i = 0; i < n; i++) cin >> p[i];
    sort(p, p + n, greater<int>());
    int ans = 0;
    for(int i = 0; i < n; i++){
      if((i+1)%m == 0) continue;
      ans += p[i];
    }
    cout << ans << endl;
  }
  return 0;
}

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

int main(){
    while (true) {
        int n;  // I will buy n vegetables.
        int m;  // One bag contains m vegetables.
        
        std::cin >> n >> m;
        std::cin.ignore();
        if ( n==0 && m==0 ) {
            return 0;
        }
        
        // input vegetable's cost.
        std::multiset<int, std::greater<int> > buy;
        int in;
        for (int i=0; i < n ; ++i) {
            std::cin >> in;
            buy.insert(in);
        }
        
        int cost = 0;  // How much must I pay?
        int x = 1;  // This is the 'x'th vegetable in the bag.
        while ( ! buy.empty() ) {
            // the first item in 'buy' is the most expensive.
            std::set<int>::iterator it = buy.begin();
            // the 'm'th item in the bag is free!
            if ( x > m-1 ) {
                x = 1;
            }else{
                cost += *it;
                ++x;
            }
            buy.erase(it);
        }
        
        // output
        std::cout << cost << std::endl;
    }
    
    return 0;
}

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

int main(){
  int n,m;
  vector<int> v;
  int ans;

  while(1){
    cin >> n >> m; 
    if(!n && !m)break;

    ans = 0;
    v.resize(n);
    for(int i=0;i<n;i++){
      cin >> v[i];
      ans += v[i];
    }
    sort(v.begin(),v.end());
    for(int i=v.size();i>=0;i-=m){
      ans -= v[i];
    }

    cout << ans << endl;
  }
}

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

int main(){
    int n,m,x;
    int flag = 0;
    int num = 0;
    int tmp;
    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]){
                tmp = v[i];
                v[i] = v[j];
                v[j] = tmp;
            }
        }
    }
    
    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>
#include <numeric>
 
int main(){
    u_int n, m;
    while(std::cin >> n >> m){
        //n??????m???0????????°??????
        if(n == 0 && m == 0){
            return 0;
        }
         
        std::vector<u_int> p(n);
        for(int i = 0; i < n; ++i){
            std::cin >> p[i];
        }
         
        std::sort(p.begin(), p.end(), std::greater<u_int>());
        //(m????????°) ????????????????????????
        for(int i = m; i <= n; i += m){
            p[i-1] = 0;
        }
         
        std::cout << std::accumulate(p.begin(), p.end(), 0) << std::endl;
    }
     
    return 0;
}