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

int price[1010];

int main(){
	cin.tie(0);
	ios::sync_with_stdio(false);
	
	int n, m;
	while(cin >> n >> m && n != 0 && m != 0){
	
		for(int i = 0; i < n; ++i){
			cin >> price[i];
		}
		
		sort(price, price + n, greater<int>());
		
		int ans = 0;
		/*int s = 0;
		while(s < n){
			int sum = 0;
			for(int i = s; i < s + m - 1 && i < n - 1; ++i){
			   sum	+= price[i];
			}
			++s;
			ans += sum;
		}*/
		/*if(m == 1){
			for(int i = 0; i < n; ++i){
				ans += price[i];
			}
			cout << ans << endl;
			return 0;
		}*/
	
		for(int i = 0; i < n; ++i){
			if((i + 1) % m != 0){
				ans += price[i];
			}
		}
		cout << ans << endl;
	}
	return 0;
}

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


int main() {
    int p[1000], n, m, i, total;

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

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

        for (i = 0, total = 0; i < n%m; i++) {
            total += p[i];
        }
        for (; i < n; i++) {
            if (i%m != n%m) {
                total += p[i];
            }
        }
        cout << total << endl;
    }
    return 0;
}

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

int main(){

	int n=0,m=0; //問題文のn,m

	while(std::cin >> n >> m){
		if(n==0&&m==0) break;
		std::array<u_int, n> p; //野菜価格一覧
		for(int i=0;i<n;i++){
			std::cin >> p[i];
		}
		std::sort(p.begin(), p.end());
		
		int price=0; //最終出力

		while(n>=m){
			for(int i=0;i<m;i++){
				price += p[n-1-i];
			}
			n -= m;
		}
		for(int i=0;i<n;i++){
			price += p[i];
		}

		std::cout << price << std::endl;
	}

	return 0;
}

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

int main() {
	int n, m;
	
	while(1){
		cin >> n >> m;
		if(n == 0 && m == 0)
			break;
			
		int p[1000];
		fill_n(p, 1000, 0);
		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 += m){
			for(int j = i; j < i + m - 1; ++j)
				ans += p[j];
		}
		
		cout << ans << endl;
	}
	return 0;
}

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

int main (){
    int n = -1, m = -1;
    while(n != 0 && m != 0){
        int ans = 0; //for answer
        std::cin >> n >> m;
        std::vector<int> price(n); //each vegetable price
        //put price to vector
        for(int i = 0; i < n; ++i){
            std::cin >> price[i];
        }
        //descending sort
        std::sort(price.begin(), price.end(), std::greater<int>());
        //m'th vegetable don't add
        for(int i = 0; i < n; ++i){
            if((i+1) % m != 0){
                ans += price[i];
            }
        }
        std::cout << ans << std::endl;
    }
    return 0;
}

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

int main(){
	std::priority_queue<int> p;
	
	int n, m;
	int price;
	while(std::cin >> n >> m){
		int sum_price = 0;
		if(n == 0 && m == 0) break;
		//input
		for(int i = 0; i < n; ++i){
			std::cin >> price;
			p.push(price);
		}
		//袋詰め
		while(!p.empty()){
			for(int i = 1; i <= m && !p.empty(); ++i){
				if(i != m){
					sum_price += p.top();
					p.pop();
				}
				else{
					p.pop();
				}
			}
		}
		std::cout << sum_price << std::endl;
	}
}

C++: #include <bits/stdc++.h>
#define FOR(i,a,b) for(int i=(a);i<(b);i++)
#define RFOR(i,a,b) for(int i=(b) - 1;i>=(a);i--)
#define REP(i,n) for(int i=0;i<(n);i++)
#define RREP(i,n) for(int i=n-1;i>=0;i--)

#define PB push_back
#define INF INT_MAX/3
#define ALL(a) (a).begin(),(a).end()
#define RALL(a) (a).rbegin(),(a).rend()
#define CLR(a) memset(a,0,sizeof(a))

typedef long long int ll;

using namespace std;

int main(){
    while(true){
	int n,m;
	cin >> n >> m;
	if(n==0&&m==0) break;
	vector<int> a(n);
	REP(i,n) cin >> a[i];
	int sum = 0;
	REP(i,n) sum += a[i];
	sort(RALL(a));
	for(int i=m-1;i<n;i+=m){
	    sum -= a[i];
	}
	cout << sum << endl;
    }
    return 0;
}

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

using namespace std;

typedef pair<int,int> pii;

#define rep(i,j) for(int i=0;i<(j);i++)
#define reps(i,j,k) for(int i=j;i<=k;i++)
#define in(i,j,k) ((i)>=(j)&&(i)<=(k))


int main(){
	int n,m,s;
	int v[1001];
	for(;;){
		scanf("%d%d",&n,&m);
		if(!n)break;
		s=0;
		rep(i,n){
			scanf("%d",v+i);
			s+=v[i];
		}
		sort(v,v+n);
		rep(i,n/m)s-=v[i*m+n%m];
		printf("%d\n",s);
	}
	return 0;
}

C++: #include <bits/stdc++.h>
#define r(i,n) for(i=0;i<n;i++)
using namespace std;
int main(){
  int a,b,i;
  while(cin>>a>>b,a){
    int c[a],s=0,k=0.p=0;
    r(i,a){cin>>c[i];p+=c[i];}
    sort(c,c+a);
    for(i=a-1;i>=0;i--){
      k++;
      if(k==b){
        s+=c[i];
        k=0;
      }
    }
    cout<<p-s<<endl;;
  }
}

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

int main(){
    int n,m,x;
    
    while(std::cin >> n >> m){
        
        if(n == 0 && m == 0)
            break;
        
        int flag = 0;
        int num = 0;
        std::vector<int> v;
        std::string line;
    
        std::getline(std::cin, line);
    
        if(std::getline(std::cin, line)){
            std::istringstream ss(line);
            while(ss >> x){
                v.push_back(x);
            }
        }
        
        sort(v.rbegin(),v.rend());
    
        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 <queue>
 
int main(){
    std::priority_queue<u_int> prices;
    u_int num_of_item, size_of_bag, price;
    
    while(1){
        std::cin >> num_of_item >> size_of_bag;
        if(num_of_item == 0 && size_of_bag == 0)
            break;
            
        for(u_int i = 0; i < num_of_item; ++i){
            std::cin >> price;
            prices.push(price);
        }
        
        u_int sum = 0;
        while(!prices.empty()){
            for(u_int i = 0; i < size_of_bag; ++i){
                if(i != size_of_bag - 1){
                    sum += prices.top();
                }
                prices.pop();
            }
        }
        std::cout << sum << std::endl;
    }
 
    return 0;
}

C++: #define _USE_MATH_DEFINES
#define INF 10000000
#include <iostream>
#include <sstream>
#include <cmath>
#include <algorithm>
#include <queue>
#include <stack>
#include <limits>
#include <map>
#include <string>
#include <cstring>
#include <set>
#include <deque>
#include <bitset>
#include <list>

using namespace std;

typedef long long ll;
typedef pair <int,int> P;
typedef pair <P,P> PP;
typedef pair <int,PP> PPP;

static const double eps = 1e-8;

int main(){
	int n,m;
	while(~scanf("%d %d",&n,&m)){
		if(n==m && m==0) break;
		int* bag = new int[n];
		for(int i=0;i<n;i++){
			scanf("%d",bag+i);
		}

		sort(bag,bag+n,greater<int>());

		int sum = 0;
		for(int i=1;i<=n;i++){
			if(i%m==0) continue;
			sum += bag[i-1];
		}
		printf("%d\n",sum);
		delete[] bag;
	}
}