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(void){
  int n,m,p[1000];

  while(1){

    int sum = 0;

    cin >> n >> m;
    if( n == 0 && m == 0 ) break;
    
    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 <algorithm>
using namespace std;
int main(){
  int n,m;
  while(cin >> n >> m , n + m){
    int yasai[1000] = {0};

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

    sort(yasai,yasai+(n+1),greater<int>());

    for(int i = n ; i >0 ; i--){
      yasai[i] = yasai[i-1];
    }
    int sum = 0;
    for(int i = 1 ; i <= n ; i++){
      if(i%m != 0)sum+=yasai[i];
    }
    cout << sum << endl;
  }
}

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

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

    while(std::cin >> n >> m){
        if(n != 0 && m != 0){
            break;
        }
        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<iostream>
using namespace std;
int main() {
	int a, b, date[11111],date2[11111],dai,kk,ans;
	while (1) {
		cin >> a >> b;
		if (a == 0 && b == 0) {
			goto a;
		}
		ans = 0;
		for (int i = 1; i <= a; i++) {
			cin >> date[i];
			ans += date[i];
		}
		for (int i = 1; i <= a; i++) {
			dai = 0;
			for (int z = 1; z <= a; z++) {
				if (dai <= date[z]) {
					dai = date[z];
					kk = z;
				}
			}
			date[kk] = 0;
			date2[i] = dai;
		}
		int ok = 0;
		while(ok<= a-b) {
			ok = ok + b;
			ans -= date2[ok];
		}
		cout << ans << endl;
	}
a:;
}

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

int main(){
  int i,j,n,m,a[1000],ans;
  while(1){
    cin >> n >> m;
    if(n == 0 && m == 0) break;
    for(i=0;i<n;i++) cin >> a[i];

    sort(a,a+n);
    ans = 0;
    j = 1;
    for(i=n-1;i>=0;i--){
      if(j == m) j = 0;
      else ans += a[i];
      j++;
    }
    cout << ans << endl;

  }
  return 0;
}

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

bool canPurchase(std::bitset<100> bit, int max_cap, int num){
    int bitcnt = 0;
    for(int i = 0; i < num; ++i){
        if(bit[i] == 1){
            ++bitcnt;
            if(!(i >= bitcnt * max_cap-1)){
                return false;
            }
        }
    }
    return true;
}

int main(){

    int purchase_num;
    int max_cap;

    while(std::cin >> purchase_num >> max_cap){
        int max = 0;
        std::string str;
        int input_data;
        std::vector<int> price;
        if(purchase_num == 0 && max_cap == 0) break;
        std::cin.ignore();
        std::getline(std::cin, str);
        std::istringstream iss(str);
        while(!iss.eof()){
            iss >> input_data;
            price.push_back(input_data);
        }
        std::sort(price.begin(),price.end(),std::greater<int>());
        std::bitset<100> select;
        int counter = pow(2.0,price.size());
        int cnt = purchase_num / max_cap;
        
        while(counter--){
            int sum = 0;
            select = static_cast<std::bitset<100> >(counter);
            if(select.count() == cnt){
                if(canPurchase(select,max_cap,purchase_num)){
                    //std::cout << select << std::endl;
                    for(int i = 0; i < price.size(); ++i){
                        if(select[i] == 1){
                            //std::cout << sum << std::endl;
                            sum += price[i];
                        }
                    }
                    if(max < sum) std::swap(max,sum);
                }
            }
        }

        int sum = 0;
        for(int i = 0; i < price.size(); ++i){
            sum += price[i];
        }
        std::cout << sum-max << std::endl;
    }
    return 0;
}

C++: #include<iostream>
#include<algorithm>
using namespace std;
int n, m, x[1000000];
long long sum1, sum2;
int main() {
	while (true) {
		sum1 = 0; sum2 = 0;
		cin >> n >> m;
		if (n == 0 && m == 0) { break; }
		for (int i = 0; i < n; i++) {
			cin >> x[i];
			sum1 += x[i];
		}
		sort(x, x + n);
		for (int i = n - m + 1; i >= 0; i -= m) {
			sum2 -= x[i];
		}
		cout << sum1 - sum2 << endl;
		return 0;
	}
}

C++: #include <iostream>
#include <algorithm>
using namespace std;
int main(){
  int n,m;
  while(cin >> n >> m , n + m){
    int yasai[1000] = {0};

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

    sort(yasai,yasai+(n+1),greater<int>());

    for(int i = n ; i >0 ; i--){
      yasai[i] = yasai[i-1];
    }
    int sum = 0;
    for(int i = 1 ; i <= n ; i++){
      if(i%m != 0)sum+=yasai[i];
    }
    cout << sum << endl;
  }
}

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

typedef long long ll;

int main()
{
    int m, n;
    while(cin >> n >> m && n && m) {
        vector<int> p(n);
        for(int i = 0; i < n; i++)
            cin >> p[i];
        
        sort(p.begin(), p.end(), greater<int>());
        
        int sum = 0;
        for(int i = 0; i < n; i++) 
            if(i / m == n / m || i % m != m - 1)
                sum += p[i];
        cout << sum << endl;
    }
}

C++: #include <iostream>
#include <algorithm>
using namespace std;
int main(){
  int n,m;
  while(cin >> n >> m , n + m){
    int yasai[1000] = {0};

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

    sort(yasai,yasai+(n+1),greater<int>());

    for(int i = n ; i >0 ; i--){
      yasai[i] = yasai[i-1];
    }
    int sum = 0;
    for(int i = 1 ; i <= n ; i++){
      if(i%m != 0)sum+=yasai[i];
    }
    cout << sum << endl;
  }
}

C++: #include <iostream>
#include <string>
#include <algorithm>
#include <numeric>
#include <boost/tokenizer.hpp>
#include <boost/lexical_cast.hpp>
#include <vector>
#include <list>

using namespace std;
using namespace boost;


int main(int argc, char* argv[])
{
	using sprtr = char_separator<char>;
	using tknzr = tokenizer<sprtr>;
	sprtr sep(" ", "", keep_empty_tokens);

	int f, mf, mo;

	string line;
	while(1) {

		int n, m;
		{
			getline(cin, line);
			tknzr tkns(line, sep);
			auto it = tkns.begin();
			n = lexical_cast<int>(*it++);
			m = lexical_cast<int>(*it);
		}

		if( n == 0 && m == 0 ) {
			break;
		}
		
		list<int> ps;		
		{
			getline(cin, line);
			tknzr tkns(line, sep);
			for( auto p : tkns ) {
				//cout << p << endl;
				ps.push_back(lexical_cast<int>(p));
			}
		}

		ps.sort(greater<int>());

		int div = n / m;
		int mod = n % m;

		int sum = 0;
		auto it = ps.begin();
		for( int i = 0; i < div; i++ ) {
			for( int j = 0; j < m; j++ ) {
				auto p = *it++;
				if( j == m-1 ) continue;
				sum += p;
			}
		}

		if( mod ) {
			for( int i = 0; i < mod; i++ ) {
				auto p = *it++;
				sum += p;			   
			}
		}

		cout << sum << endl;

		ps.clear();
		
	}

    return 0;
}