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>
#define MAX 1000;
using namespace std;

int main(){
  int n,m,s;

  while(cin >> n >> m){
    int p[n];
    if(n==0 || m==0) return 0;
    for(int i=0; i<n; i++){
      cin >> p[i];
    }   

    int sum=0,ans=0, min;
    sort(p, p+n, greater<int>());

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

C++: #include <iostream>
#include <vector>
#include <algorithm>
int main() {
	int n, m;
	std::cin >> n >> m;
	while (n != 0 && m != 0) {
		int whole_price = 0;
		std::vector<int> vegi(n);
		for (auto &v : vegi) std::cin >> v;
		std::sort(vegi.begin(), vegi.end());
		for (auto i = 1; i <= n; ++i) {
			whole_price += (i % m == 0) ? 0 : vegi[n - i];
		}
		std::cout << whole_price << std::endl;
		std::cin >> n >> m;
	}
}

C++: #include<bits/stdc++.h>
using namespace std;
int main(){
  int n,m,sum=0,d;
  int p[1010]={};
  while(1){
    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);
    reverse(p,p+n);
    for(int i=1; i<n+m; i++){
      d = m*i-1;
      sum -= p[d];
    }
    cout << sum << endl;
  }
  return 0;
}

C++: #include<stdio.h>
#include<stdlib.h>
int comp(const void *a,const void *b){
	return *(int*)b-*(int*)a;
}

int main(){
	int n,m;
	int p[1000];
	int i,j;
	int ans;
	while(1){
		scanf("%d %d",&n,&m);
		if(n==0)return 0;
		ans=0;
		for(i=0;i<n;i++)scanf("%d",&p[i]);
		qsort(p,n,sizeof(int),comp);
		printf("%d\n",p[0]);
		for(i=0;i<n;i++){
			if(i%m!=m-1)ans+=p[i];
		}
		printf("%d\n",ans);
	}
}

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];

    }

    sort( p , p + n );

    for( int i = 0 ; i < n ; i++ ) 
      if( (i+1)%m != m-1  ) sum += p[i];

    cout << sum << endl;

  }

  return 0;
}

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

int main(){

    int purchase_num;
    int max_cap;

    while(std::cin >> purchase_num >> max_cap){
        if(purchase_num == 0 && max_cap == 0) break;
        std::vector<int> price;
        std::string str;
        int input_data;
        int min_price = 0;
        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>());
        for(int i = 0; i < price.size(); ++i){
            if((i+1)%max_cap != 0){
                min_price += price[i];
            }
        }
        std::cout << min_price << std::endl;
    }
    return 0;
}

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

int main(){
	int m,n;
	while(std::cin >> n >> m){
		int sum_cost = 0;
		std::priority_queue<int> vegetable;
		for(int i = 0; i < n; ++i){
			int cost;
			std::cin >> cost;
			vegetable.push(cost);
		}
		
		for(int i = 1; i <= n; ++i){
			if((i % m) != 0){
				sum_cost += vegetable.top();
				vegetable.pop();
			}
			else
				vegetable.pop();
		}
		std::cout << sum_cost << 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 >> vegetable;
			que.push(vegetable);
		}
		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<string>
#include<algorithm>
using namespace std;
int main() {
	int m, n;
	while (cin >> n >> m&&n != 0 && m != 0) {
		int a = n%m, b = (n - a) / m, d = 0, e[1000], sum = 0;
		string c, h = "";
		getline(cin, c);
		getline(cin, c);
		c += " ";
		for (int i = 0; i < c.length(); i++) {
			if (c[i] == ' ') {
				e[d] = atoi(h.c_str());
				h = "";
				d++;
			}
			else
				h += c[i];
		}
		sort(e, e + n);
		d = 0;
		for (int i = 0; i < a; i++) {
			sum += e[i];
			d++;
		}
		for (int i = 0; i < b; i++) {
			for (int j = 0; j < m; j++) {
				if (j != 0) {
					sum += e[i*m + j+a];
				}
			}
		}
		cout << sum << endl;
	}
}

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

int main(){
	int purchase, capa;
	
	while(std::cin >> purchase >> capa){
		if(purchase == 0 && capa == 0)
			break;
		
		std::vector<int> vegetable_price;
		vegetable_price.resize(purchase);
		
		//input
		for(int i=0; i<purchase; ++i){
			std::cin >> vegetable_price[i];
		}
		
		std::sort(vegetable_price.begin(), vegetable_price.end(), std::greater<int>());
		
		// 
		for(size_t i=capa-1; i<vegetable_price.size(); i += capa-1){
			vegetable_price.erase(vegetable_price.begin() + i);
		}
		
		int sum_price = 0;
		for(size_t i=0; i<vegetable_price.size(); ++i){
			sum_price += vegetable_price[i];
		}
		
		//show
		std::cout << sum_price << std::endl;
		
	}
	
	return 0;
}

C++: #include <iostream>
#include <vector>
#include <algorithm>
#include <numeric>
    
int main(){
    u_int n;    // the number of vegetable
    u_int m;    // capacity
       
    while(std::cin >> n >> m){
        if(n == 0 && m == 0){
            break;
        }
            
        std::vector<u_int> p(n);  // price
        for(int i = 0; i < n; ++i){
            std::cin >> p[i];
        }
           
        //m, 2*m, 3*m, ... = free(sort by descending)
        std::sort(p.begin(), p.end(), std::greater<u_int>());
        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;
}

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; i >= 0; i -= m) {
			sum2 += x[i];
		}
		cout << sum1 - sum2 << endl;
	}
	return 0;
}

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

int main(void){
	int num_veg,bag,price,sum_price;
	std::vector<int> price_veg;
	
	while(std::cin >> num_veg >> bag){
		if(num_veg == 0 && bag == 0) break;
		
		for(int i = 0; i < num_veg; ++i){
			std::cin >> price;
			price_veg.push_back(price);
		}

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

		sum_price = 0;
		for(int j = 0; j < num_veg; ++j){
			if(j % bag != bag - 1) sum_price += price_veg[j];
		}

		std::cout << sum_price << std::endl;
	}


	return 0;
}