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>
using namespace std;
int main(){
  int n,m;
  int p[1001];
  while(1){
    int ans=0;
    cin>>n>>m;
    if(n+m==0)break;
    for(int i=0;i<n;i++)
      cin>>p[i];
    
    for(int i=0;i<n;i++) 
      for(int i=0;i<n;i++)
	if(p[i]<p[i+1])swap(p[i],p[i+1]);
    
    for(int i=0;i<n;i++)
      if((i+1)%m==0)p[i]=0;
    
    for(int i=0;i<n;i++)ans+=p[i];
    
    cout<<ans<<endl;
  }
}

C++: #include<bits/stdc++.h>
using namespace std ;

main(){
	int n , m ;
	int c[1010] ;
	while( cin >> n >> m , n , m ){
		for( int i=0 ; i<n ; i++ ) cin >> c[i] ;
		sort(c,c+n,greater<int>()) ;
		int sum = 0 ;
		for( int i=0 ; i<n ; i++ ){
			if( (i+1)%m ){
				sum += c[i] ;
				cout << i << " " << c[i] << endl ;
			}
		}
		cout << sum << endl ;
	}
}

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

void selectionsort(int A[], int N){
  int minj;
  for(int i=N-1;i>=0;i--){
    minj = i;
    for(int j=i-1;j>=0;j--){
      if(A[j]<A[minj]) minj = j;
    }
    if(minj != i){
      swap(A[minj], A[i]);
    }
  }
}

int main(){
  int n, m;
  while(1){
    int sum = 0;
    cin>>n>>m;
    if(!(n * m)) return 0;
    int  P[1000];
    for(int i=0;i<n;i++){
      cin>>P[i];
      sum += P[i];
    }
    selectionsort(P, n);
    for(int i=1;i<=n/m;i++){
      sum -= P[i*m-1];
    }
    cout<<sum<<endl;
  }
}

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

int main(){
	int n, m, tmp;
	while(cin >> n >> m){
		vector<int> v;
		int ans = 0;
		if(n == 0 && m == 0) break;
		for(int i = 0; i < n; i++){
			cin >> tmp;
			v.push_back(tmp);			
		}
		sort(v.begin(), v.end(), greater<int>());
		for(vector<int>::iterator it = v.begin(); it < v.end();){
			int tmp = 100000;
			int i;
			for(i = 0; i < m; i++){
				if(*it <= tmp) tmp = *it;
				ans += *it;
				it++;
//				if(it == v.end()) break;
			}
			if(i == m){
				ans -= tmp;
			}
		}
		cout << ans << endl;
		ans = 0;
	}


}

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

#define REP(i,k,n) for(int i=k;i<n;i++)
#define rep(i,n) for(int i=0;i<n;i++)

using namespace std;

int main()
{
	int n,m;
	while(cin >> n >> m)
	{
		if(n == 0 && m == 0) break;
		
		vector<int> v;
		v.resize(n);

		rep(i,n) cin >> v[i];
		sort(v.begin(),v.end());
		
		int ans = 0;
		for(int i=n-1;i>=0;i -= m)
		{
			if(i-m+1 < 0)
			{
				for(int j=i;j>=0;j--)
				{
					ans += v[j];
				}
			}
			else
			{
				for(int j=i;j>(i-m+1);j--)
				{
					ans += v[j];
				}
			}
		}
		cout << ans << endl;

	}
}

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

int main(){

	int num, limit;

	while(std::cin >> num >> limit){
		std::vector<int> price;
		int sum_price = 0;
		//input
		for(int i = 0; i < num; ++i){
			int buf;
			sum_price += buf;
			std::sin >> buf;
			price.push_back(buf);
		}
		//sort
		std::sort(price.begin(),price.end(),std::greater<int>());
		//discount
		int discount = 0;
		int in_bag = 0;
		for(auto itr = price.begin; itr != price.end(); ++itr){
			++in_bag;
			if(in_bag == limit){
				discount += itr;
				in_bag = 0;
			}
		}

		std::cout << sum_price - dicount << std::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>

using namespace std;

vector<int> money;
void del(int,int);
int add ();

int main() {
	int n,m,p,sum;
	
	while ( cin >> n, cin >> m, n, m ) {
		//初期化
		money.clear();
		
		
		for ( int i = 0; i < n; i++ ) {
			cin >> p;
			money.push_back ( p );
		}
		
		sort( money.begin() , money.end() , greater<int>() );
		del (n / m , m);
		sum = add ();
		
		cout << sum << endl;
	}
	return 0;
}

void del(int hoge , int m) {
	vector<int>::iterator it = money.begin();
	for( int i = 1; i <= hoge; i++ ) {
		money.erase( money.begin() +  (i * m - i) );
	}
}

int add () {
	int sum = 0;
	
	vector<int>::iterator it = money.begin();
	while( it != money.end() ) {
		sum += *it;
		it++;
	}
	return sum;
}

C++: #include<iostream>
#include<algorithm>
#include<functional>
#define MAX 1000
int main(){
	int n,m,p[MAX];
	while(1){
		int f=0,m=0;
		std::cin>>n>>m;
		if(n==0&&m==0)
			break;
		for(int i=0;i<n;++i){
			std::cin>>p[i];
		    m+=p[i];
		}
		std::sort(p+1,p+n+1,std::greater<int>());
		int c=n%m;
		for(int i=0;i<n-c;++i){
			if(i+1%m==0)
				f+=p[i];
		}
		std::cout<<m-f<<std::endl;
	}
	return 0;
}

C++: #include<iostream>
using namespace std;
int main(){
  int n,m;
  int p[1001];
  while(1){
    int ans=0;
    cin>>n>>m;
    if(n+m==0)break;
    for(int i=0;i<n;i++)
      cin>>p[i];
    
    for(int j=0;j<n;j++) 
      for(int i=0;i<n;i++)
	if(p[i]<p[i+1])swap(p[i],p[i+1]);

    for(int i=0;i<n;i++)
      if((i+1)%m==0)p[i]=0;
    
    for(int i=0;i<n;i++)ans+=p[i];
    
    cout<<ans<<endl;
  }
  return 0;
}

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

int main(){
	int n, m; // n:konyu m:hukuro
	std::cin >> n >> m;
	while(n != 0 || m != 0){
		std::vector<int> price;
		price.resize(n);
		for(int i = 0; i < n; ++i){
			std::cin >> price[i]; // input
		}
		
		std::sort(price.begin(), price.end(), std::greater<int>());

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

		std::cout << sum << std::endl;
		std::cin >> n >> m; 
	}

	return 0;
}

C++: #include<bits/stdc++.h>
using namespace std;
#define MAX 1000
main() {
	int n, m, P[MAX], sum;
	while(1) {
		cin >> n >> m;
		if ( n == 0 && m == 0 ) break;
		sum = 0;
		for ( int i = 0; i < n; i++ ) {
			cin >> P[i];
			sum += P[i];
		}
		sort(P, P+n, greater<int>());
		for ( int i = m-1; i < n; i += m ) sum -= P[i];
		cout << sum << endl;
	}
}

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

C++: #include<iostream>
#include<algorithm>
using namespace std;
main(){
  int ans=0;
  int be[10002];
  int x=-1,n,m;
  while(1){
    x=-1;
    ans=0;
    cin>>n>>m;
    if(m==0&&n==0)break;
    for(int i=0;i<n;i++){
      cin>>be[i];
      ans+=be[i];
    }
    sort(be,be+n,greater<int>());
    while(n>=m){
      x+=m;
      ans-=be[x];
      n-=m;
    }
    cout<<ans<<endl;
  }
}