Search is not available for this dataset
name
stringlengths 2
112
| description
stringlengths 29
13k
| source
int64 1
7
| difficulty
int64 0
25
| solution
stringlengths 7
983k
| language
stringclasses 4
values |
---|---|---|---|---|---|
p00095 Surf Smelt Fishing Contest | A smelt fishing tournament was held at Lake Hibara. The winner is the one who wins the most smelt.
Create a program that reads the list of participant numbers and the number of fish caught and outputs the number of winners and the number of fish caught. If there are multiple winners, output the one with the lowest participant number.
input
The input is given in the following format.
n
a1 v1
a2 v2
::
an vn
n (1 ≤ n ≤ 20) represents the number of participants and ai represents the participant number. Participant numbers are different integers between 1 and n. vi (0 ≤ vi ≤ 100) is the number of animals acquired by the participant ai.
output
Output the winner's participant number and the number of fish caught on one line separated by blanks.
Example
Input
6
1 14
2 25
3 42
4 11
5 40
6 37
Output
3 42 | 7 | 0 | #include<iostream>
#include<stdio.h>
using namespace std;
int main(){
int a[30]={0},p,q,m=0,b=1;
int n;
cin>>n;
for(int i=0;i<n;i++){
cin>>p>>q;
a[p]+=q;
}
for(int i=0;i<30;i++){
if(m<a[i]){
m=a[i];
b=i;
}
}
cout<<b<<" "<<m<<endl;
} | CPP |
p00095 Surf Smelt Fishing Contest | A smelt fishing tournament was held at Lake Hibara. The winner is the one who wins the most smelt.
Create a program that reads the list of participant numbers and the number of fish caught and outputs the number of winners and the number of fish caught. If there are multiple winners, output the one with the lowest participant number.
input
The input is given in the following format.
n
a1 v1
a2 v2
::
an vn
n (1 ≤ n ≤ 20) represents the number of participants and ai represents the participant number. Participant numbers are different integers between 1 and n. vi (0 ≤ vi ≤ 100) is the number of animals acquired by the participant ai.
output
Output the winner's participant number and the number of fish caught on one line separated by blanks.
Example
Input
6
1 14
2 25
3 42
4 11
5 40
6 37
Output
3 42 | 7 | 0 | n = int(input())
a = [0 for i in range(n)]
v = [0 for i in range(n)]
for i in range(n):
a[i], v[i] = [int(i) for i in input().split()]
v1 = sorted(v)
max_ = v1[-1]
indexes = [i for i, x in enumerate(v) if x == max_]
a_ = min([a[i] for i in indexes])
print(a_,max_)
| PYTHON3 |
p00095 Surf Smelt Fishing Contest | A smelt fishing tournament was held at Lake Hibara. The winner is the one who wins the most smelt.
Create a program that reads the list of participant numbers and the number of fish caught and outputs the number of winners and the number of fish caught. If there are multiple winners, output the one with the lowest participant number.
input
The input is given in the following format.
n
a1 v1
a2 v2
::
an vn
n (1 ≤ n ≤ 20) represents the number of participants and ai represents the participant number. Participant numbers are different integers between 1 and n. vi (0 ≤ vi ≤ 100) is the number of animals acquired by the participant ai.
output
Output the winner's participant number and the number of fish caught on one line separated by blanks.
Example
Input
6
1 14
2 25
3 42
4 11
5 40
6 37
Output
3 42 | 7 | 0 | #include<iostream>
#include<map>
#include<vector>
#include<algorithm>
using namespace std;
typedef pair<int,pair<int,int> > P;
int main(void){
pair<int,pair<int,int> > p;
vector<P> v;
int n,a,b;
cin >> n;
for(int i = 0;i < n; i++){
cin >> p.second.second >> p.first;
p.second.first = 100 - p.second.second;
v.push_back(p);
}
sort(v.begin(),v.end());
cout << v[v.size()-1].second.second << " " << v[v.size()-1].first << endl;
}
| CPP |
p00095 Surf Smelt Fishing Contest | A smelt fishing tournament was held at Lake Hibara. The winner is the one who wins the most smelt.
Create a program that reads the list of participant numbers and the number of fish caught and outputs the number of winners and the number of fish caught. If there are multiple winners, output the one with the lowest participant number.
input
The input is given in the following format.
n
a1 v1
a2 v2
::
an vn
n (1 ≤ n ≤ 20) represents the number of participants and ai represents the participant number. Participant numbers are different integers between 1 and n. vi (0 ≤ vi ≤ 100) is the number of animals acquired by the participant ai.
output
Output the winner's participant number and the number of fish caught on one line separated by blanks.
Example
Input
6
1 14
2 25
3 42
4 11
5 40
6 37
Output
3 42 | 7 | 0 | #include <iostream>
using namespace std;
int main(){
int n;
cin >> n;
int max=-1; int kouho =0;
for(int i=0;i<n;i++){
int a,b;
cin >> a >> b;
if(max == b && kouho > a){
kouho = a;
}
if(max < b){
max = b;
kouho = a;
}
}
cout << kouho << " " << max << endl;
} | CPP |
p00095 Surf Smelt Fishing Contest | A smelt fishing tournament was held at Lake Hibara. The winner is the one who wins the most smelt.
Create a program that reads the list of participant numbers and the number of fish caught and outputs the number of winners and the number of fish caught. If there are multiple winners, output the one with the lowest participant number.
input
The input is given in the following format.
n
a1 v1
a2 v2
::
an vn
n (1 ≤ n ≤ 20) represents the number of participants and ai represents the participant number. Participant numbers are different integers between 1 and n. vi (0 ≤ vi ≤ 100) is the number of animals acquired by the participant ai.
output
Output the winner's participant number and the number of fish caught on one line separated by blanks.
Example
Input
6
1 14
2 25
3 42
4 11
5 40
6 37
Output
3 42 | 7 | 0 | #include<bits/stdc++.h>
using namespace std;
int main()
{
int n,men,fish,num,fishmax;
cin>>n;
for(int i=0;i<n;i++){
cin>>men>>fish;
if(i==0){
num=men;
fishmax=fish;
}
else {
if(fish>fishmax){
fishmax=fish;
num=men;
}
else if(num>men&&fish==fishmax)num=men;
}
}
cout<<num<<" "<<fishmax<<endl;
} | CPP |
p00095 Surf Smelt Fishing Contest | A smelt fishing tournament was held at Lake Hibara. The winner is the one who wins the most smelt.
Create a program that reads the list of participant numbers and the number of fish caught and outputs the number of winners and the number of fish caught. If there are multiple winners, output the one with the lowest participant number.
input
The input is given in the following format.
n
a1 v1
a2 v2
::
an vn
n (1 ≤ n ≤ 20) represents the number of participants and ai represents the participant number. Participant numbers are different integers between 1 and n. vi (0 ≤ vi ≤ 100) is the number of animals acquired by the participant ai.
output
Output the winner's participant number and the number of fish caught on one line separated by blanks.
Example
Input
6
1 14
2 25
3 42
4 11
5 40
6 37
Output
3 42 | 7 | 0 | #include<iostream>
#include<vector>
#include<algorithm>
using namespace std;
typedef pair<int,int> P;
int main(){
int n;
cin>>n;
vector<P> data;
for(int i=0; i<n; i++) {
int a, v;
cin>>a>>v;
data.push_back(P(-v,a));
}
sort(data.begin(),data.end());
cout<<data[0].second<<" "<<-data[0].first<<endl;
} | CPP |
p00095 Surf Smelt Fishing Contest | A smelt fishing tournament was held at Lake Hibara. The winner is the one who wins the most smelt.
Create a program that reads the list of participant numbers and the number of fish caught and outputs the number of winners and the number of fish caught. If there are multiple winners, output the one with the lowest participant number.
input
The input is given in the following format.
n
a1 v1
a2 v2
::
an vn
n (1 ≤ n ≤ 20) represents the number of participants and ai represents the participant number. Participant numbers are different integers between 1 and n. vi (0 ≤ vi ≤ 100) is the number of animals acquired by the participant ai.
output
Output the winner's participant number and the number of fish caught on one line separated by blanks.
Example
Input
6
1 14
2 25
3 42
4 11
5 40
6 37
Output
3 42 | 7 | 0 | n = int(input())
ma = 20
mv = 0
while n > 0:
a,v = map(int,input().split())
if mv < v:
ma,mv = a,v
elif mv == v and ma >= a:
ma,mv = a,v
n -= 1
print(ma,mv) | PYTHON3 |
p00095 Surf Smelt Fishing Contest | A smelt fishing tournament was held at Lake Hibara. The winner is the one who wins the most smelt.
Create a program that reads the list of participant numbers and the number of fish caught and outputs the number of winners and the number of fish caught. If there are multiple winners, output the one with the lowest participant number.
input
The input is given in the following format.
n
a1 v1
a2 v2
::
an vn
n (1 ≤ n ≤ 20) represents the number of participants and ai represents the participant number. Participant numbers are different integers between 1 and n. vi (0 ≤ vi ≤ 100) is the number of animals acquired by the participant ai.
output
Output the winner's participant number and the number of fish caught on one line separated by blanks.
Example
Input
6
1 14
2 25
3 42
4 11
5 40
6 37
Output
3 42 | 7 | 0 | #include<iostream>
using namespace std;
int main(){
int n,x,y=-1;
cin>>n;
while(n--){
int a,b;
cin>>a>>b;
if(y<b || b==y&&a<x)x=a,y=b;
}
cout<<x<<' '<<y<<endl;
return 0;
} | CPP |
p00095 Surf Smelt Fishing Contest | A smelt fishing tournament was held at Lake Hibara. The winner is the one who wins the most smelt.
Create a program that reads the list of participant numbers and the number of fish caught and outputs the number of winners and the number of fish caught. If there are multiple winners, output the one with the lowest participant number.
input
The input is given in the following format.
n
a1 v1
a2 v2
::
an vn
n (1 ≤ n ≤ 20) represents the number of participants and ai represents the participant number. Participant numbers are different integers between 1 and n. vi (0 ≤ vi ≤ 100) is the number of animals acquired by the participant ai.
output
Output the winner's participant number and the number of fish caught on one line separated by blanks.
Example
Input
6
1 14
2 25
3 42
4 11
5 40
6 37
Output
3 42 | 7 | 0 | import java.util.*;
public class Main {
static Scanner sc = new Scanner(System.in);
static int[][] fishingData;
static int n;
public static void main(String[] args) {
while(read()){
solve();
}
}
static boolean read(){
if( !sc.hasNext() )return false;
n = sc.nextInt();
fishingData = new int[n][2];
for(int i = 0; i < fishingData.length; i++){
fishingData[i][0] = sc.nextInt();
fishingData[i][1] = sc.nextInt();
}
return true;
}
static void solve(){
int max = -1;
for(int i = 0; i < fishingData.length; i++){
max = Math.max(max, fishingData[i][1]);
}
int res = 1<<29;
for(int i = 0; i < fishingData.length; i++){
if( fishingData[i][1] == max ){
res = Math.min(res, fishingData[i][0]);
}
}
System.out.println(res + " " + max);
}
} | JAVA |
p00095 Surf Smelt Fishing Contest | A smelt fishing tournament was held at Lake Hibara. The winner is the one who wins the most smelt.
Create a program that reads the list of participant numbers and the number of fish caught and outputs the number of winners and the number of fish caught. If there are multiple winners, output the one with the lowest participant number.
input
The input is given in the following format.
n
a1 v1
a2 v2
::
an vn
n (1 ≤ n ≤ 20) represents the number of participants and ai represents the participant number. Participant numbers are different integers between 1 and n. vi (0 ≤ vi ≤ 100) is the number of animals acquired by the participant ai.
output
Output the winner's participant number and the number of fish caught on one line separated by blanks.
Example
Input
6
1 14
2 25
3 42
4 11
5 40
6 37
Output
3 42 | 7 | 0 | #include <iostream>
using namespace std;
int main()
{
int n;
while( cin >> n ){
int ansA, ansV;
ansA = 100, ansV = 0;
for( int i = 0; i < n; ++i ){
int a, v;
cin >> a >> v;
if( ansV < v ){
ansA = a;
ansV = v;
}else if( ansV == v && ansA > a ){
ansA = a;
}
}
cout << ansA << " " << ansV << endl;
}
return 0;
} | CPP |
p00095 Surf Smelt Fishing Contest | A smelt fishing tournament was held at Lake Hibara. The winner is the one who wins the most smelt.
Create a program that reads the list of participant numbers and the number of fish caught and outputs the number of winners and the number of fish caught. If there are multiple winners, output the one with the lowest participant number.
input
The input is given in the following format.
n
a1 v1
a2 v2
::
an vn
n (1 ≤ n ≤ 20) represents the number of participants and ai represents the participant number. Participant numbers are different integers between 1 and n. vi (0 ≤ vi ≤ 100) is the number of animals acquired by the participant ai.
output
Output the winner's participant number and the number of fish caught on one line separated by blanks.
Example
Input
6
1 14
2 25
3 42
4 11
5 40
6 37
Output
3 42 | 7 | 0 | #include<iostream>
#include<cstring>
#include<algorithm>
#include<string>
#include<vector>
#include<cstdio>
#include<cmath>
#define pb(in,tmp) in.push_back(tmp)
#define loop(i,a,b) for(int i=a;i<b;i++)
#define rep(i,b) loop(i,0,b)
#define all(in) in.begin(),in.end()
using namespace std;
int main(){
int n;
cin>>n;
vector<int>in;
vector<int>no;
rep(i,n){
int a,b;
cin>>a>>b;
pb(in,b);
pb(no,a);
}
rep(i,100*n){
rep(j,n-1){
if(in[j]<in[j+1]){swap(in[j],in[j+1]);swap(no[j],no[j+1]);}
if(in[j]==in[j+1]&&no[j]>no[j+1])swap(no[j],no[j+1]);
}
}
cout<<no[0]<<" "<<in[0]<<endl;
} | CPP |
p00095 Surf Smelt Fishing Contest | A smelt fishing tournament was held at Lake Hibara. The winner is the one who wins the most smelt.
Create a program that reads the list of participant numbers and the number of fish caught and outputs the number of winners and the number of fish caught. If there are multiple winners, output the one with the lowest participant number.
input
The input is given in the following format.
n
a1 v1
a2 v2
::
an vn
n (1 ≤ n ≤ 20) represents the number of participants and ai represents the participant number. Participant numbers are different integers between 1 and n. vi (0 ≤ vi ≤ 100) is the number of animals acquired by the participant ai.
output
Output the winner's participant number and the number of fish caught on one line separated by blanks.
Example
Input
6
1 14
2 25
3 42
4 11
5 40
6 37
Output
3 42 | 7 | 0 | #include<iostream>
#include<algorithm>
#include<vector>
using namespace std;
typedef pair<int,int> P;
bool cmp(const P& a,const P& b)
{
if(a.first == b.first)
return a.second < b.second;
return a.first > b.first;
}
int main()
{
int n;
vector<P> vec;
cin >> n;
for(int i=0;i<n;i++)
{
int a,v;
cin >> a >> v;
vec.push_back(P(v,a));
}
sort(vec.begin(),vec.end(),cmp);
cout << vec[0].second << " " << vec[0].first << endl;
return 0;
} | CPP |
p00095 Surf Smelt Fishing Contest | A smelt fishing tournament was held at Lake Hibara. The winner is the one who wins the most smelt.
Create a program that reads the list of participant numbers and the number of fish caught and outputs the number of winners and the number of fish caught. If there are multiple winners, output the one with the lowest participant number.
input
The input is given in the following format.
n
a1 v1
a2 v2
::
an vn
n (1 ≤ n ≤ 20) represents the number of participants and ai represents the participant number. Participant numbers are different integers between 1 and n. vi (0 ≤ vi ≤ 100) is the number of animals acquired by the participant ai.
output
Output the winner's participant number and the number of fish caught on one line separated by blanks.
Example
Input
6
1 14
2 25
3 42
4 11
5 40
6 37
Output
3 42 | 7 | 0 | import java.util.Scanner;
public class Main {
public static void main(String[] args){
Scanner sc=new Scanner(System.in);
int n=sc.nextInt();
int a;
int v;
int maxPtr=0;
int max=Integer.MIN_VALUE;
for(int i=0;i<n;i++){
a=sc.nextInt();
v=sc.nextInt();
if(v>max){
max=v;
maxPtr=a;
}else if(max==v&&a<maxPtr){
max=v;
maxPtr=a;
}
}
System.out.println(maxPtr+" "+max);
}
} | JAVA |
p00095 Surf Smelt Fishing Contest | A smelt fishing tournament was held at Lake Hibara. The winner is the one who wins the most smelt.
Create a program that reads the list of participant numbers and the number of fish caught and outputs the number of winners and the number of fish caught. If there are multiple winners, output the one with the lowest participant number.
input
The input is given in the following format.
n
a1 v1
a2 v2
::
an vn
n (1 ≤ n ≤ 20) represents the number of participants and ai represents the participant number. Participant numbers are different integers between 1 and n. vi (0 ≤ vi ≤ 100) is the number of animals acquired by the participant ai.
output
Output the winner's participant number and the number of fish caught on one line separated by blanks.
Example
Input
6
1 14
2 25
3 42
4 11
5 40
6 37
Output
3 42 | 7 | 0 | #include <iostream>
#include <string>
#include <vector>
#include <map>
#include <algorithm>
using namespace std;
int main() {
int n;
cin >> n;
vector<pair<int,int>> list;
for (int i=0; i<n; ++i) {
int a, v;
cin >> a >> v;
list.push_back(make_pair(-v, a));
}
sort(list.begin(), list.end());
cout << list[0].second << " " << -list[0].first << endl;
return 0;
} | CPP |
p00095 Surf Smelt Fishing Contest | A smelt fishing tournament was held at Lake Hibara. The winner is the one who wins the most smelt.
Create a program that reads the list of participant numbers and the number of fish caught and outputs the number of winners and the number of fish caught. If there are multiple winners, output the one with the lowest participant number.
input
The input is given in the following format.
n
a1 v1
a2 v2
::
an vn
n (1 ≤ n ≤ 20) represents the number of participants and ai represents the participant number. Participant numbers are different integers between 1 and n. vi (0 ≤ vi ≤ 100) is the number of animals acquired by the participant ai.
output
Output the winner's participant number and the number of fish caught on one line separated by blanks.
Example
Input
6
1 14
2 25
3 42
4 11
5 40
6 37
Output
3 42 | 7 | 0 | #include <iostream>
#include <algorithm>
using namespace std;
int main() {
int n;
pair<int,int> ans(1,0);
cin >> n;
while(n--) {
int a, v;
cin >> a >> v;
ans = min(ans, make_pair(-v, a));
}
cout << ans.second << " " << -ans.first << endl;
return 0;
} | CPP |
p00095 Surf Smelt Fishing Contest | A smelt fishing tournament was held at Lake Hibara. The winner is the one who wins the most smelt.
Create a program that reads the list of participant numbers and the number of fish caught and outputs the number of winners and the number of fish caught. If there are multiple winners, output the one with the lowest participant number.
input
The input is given in the following format.
n
a1 v1
a2 v2
::
an vn
n (1 ≤ n ≤ 20) represents the number of participants and ai represents the participant number. Participant numbers are different integers between 1 and n. vi (0 ≤ vi ≤ 100) is the number of animals acquired by the participant ai.
output
Output the winner's participant number and the number of fish caught on one line separated by blanks.
Example
Input
6
1 14
2 25
3 42
4 11
5 40
6 37
Output
3 42 | 7 | 0 | #include<bits/stdc++.h>
using namespace std;
int main(){
int n;
cin>>n;
vector<pair<int,int> >vec;
for(int i=0;i<n;i++){
int a,b;
cin>>a>>b;
vec.push_back(pair<int,int>(-b,a));
}
sort(vec.begin(),vec.end());
cout<<vec[0].second<<" "<<-vec[0].first<<endl;
return 0;
} | CPP |
p00095 Surf Smelt Fishing Contest | A smelt fishing tournament was held at Lake Hibara. The winner is the one who wins the most smelt.
Create a program that reads the list of participant numbers and the number of fish caught and outputs the number of winners and the number of fish caught. If there are multiple winners, output the one with the lowest participant number.
input
The input is given in the following format.
n
a1 v1
a2 v2
::
an vn
n (1 ≤ n ≤ 20) represents the number of participants and ai represents the participant number. Participant numbers are different integers between 1 and n. vi (0 ≤ vi ≤ 100) is the number of animals acquired by the participant ai.
output
Output the winner's participant number and the number of fish caught on one line separated by blanks.
Example
Input
6
1 14
2 25
3 42
4 11
5 40
6 37
Output
3 42 | 7 | 0 | from operator import itemgetter
n = int(input())
rs = [list(map(int,input().split())) for i in range(n)]
rs = sorted(rs,key=itemgetter(0))
print(' '.join(map(str, sorted(rs, key=itemgetter(1),reverse=True)[0]))) | PYTHON3 |
p00095 Surf Smelt Fishing Contest | A smelt fishing tournament was held at Lake Hibara. The winner is the one who wins the most smelt.
Create a program that reads the list of participant numbers and the number of fish caught and outputs the number of winners and the number of fish caught. If there are multiple winners, output the one with the lowest participant number.
input
The input is given in the following format.
n
a1 v1
a2 v2
::
an vn
n (1 ≤ n ≤ 20) represents the number of participants and ai represents the participant number. Participant numbers are different integers between 1 and n. vi (0 ≤ vi ≤ 100) is the number of animals acquired by the participant ai.
output
Output the winner's participant number and the number of fish caught on one line separated by blanks.
Example
Input
6
1 14
2 25
3 42
4 11
5 40
6 37
Output
3 42 | 7 | 0 | n=input()
a0,v0=n,0
for i in range(n):
a,v=map(int,raw_input().split())
if v>v0: a0,v0=a,v
elif v==v0: a0=min(a0,a)
print a0,v0 | PYTHON |
p00095 Surf Smelt Fishing Contest | A smelt fishing tournament was held at Lake Hibara. The winner is the one who wins the most smelt.
Create a program that reads the list of participant numbers and the number of fish caught and outputs the number of winners and the number of fish caught. If there are multiple winners, output the one with the lowest participant number.
input
The input is given in the following format.
n
a1 v1
a2 v2
::
an vn
n (1 ≤ n ≤ 20) represents the number of participants and ai represents the participant number. Participant numbers are different integers between 1 and n. vi (0 ≤ vi ≤ 100) is the number of animals acquired by the participant ai.
output
Output the winner's participant number and the number of fish caught on one line separated by blanks.
Example
Input
6
1 14
2 25
3 42
4 11
5 40
6 37
Output
3 42 | 7 | 0 | #include<cstdio>
#include<cstring>
#include<iostream>
#include<algorithm>
using namespace std;
int main()
{
int n,a[20],v[100],deta;
cin>>n;
for(int i=0;i<n;i++)cin>>a[i]>>v[i];
for(int i=0;i<n-1;i++)for(int j=0;j<n-1;j++)
{
if(v[j]<v[j+1]||(v[j]==v[j+1]&&a[j]>a[j+1]))
{
deta=v[j];
v[j]=v[j+1];
v[j+1]=deta;
deta=a[j];
a[j]=a[j+1];
a[j+1]=deta;
}
}
cout<<a[0]<<" "<<v[0]<<endl;
return 0;
} | CPP |
p00095 Surf Smelt Fishing Contest | A smelt fishing tournament was held at Lake Hibara. The winner is the one who wins the most smelt.
Create a program that reads the list of participant numbers and the number of fish caught and outputs the number of winners and the number of fish caught. If there are multiple winners, output the one with the lowest participant number.
input
The input is given in the following format.
n
a1 v1
a2 v2
::
an vn
n (1 ≤ n ≤ 20) represents the number of participants and ai represents the participant number. Participant numbers are different integers between 1 and n. vi (0 ≤ vi ≤ 100) is the number of animals acquired by the participant ai.
output
Output the winner's participant number and the number of fish caught on one line separated by blanks.
Example
Input
6
1 14
2 25
3 42
4 11
5 40
6 37
Output
3 42 | 7 | 0 | #include<bits/stdc++.h>
#define rep(i,n)for(int i=0;i<n;i++)
using namespace std;
typedef pair<int, int>P;
map<int, int>mp;
int main() {
int n; cin >> n;
rep(i, n) {
int a, v; cin >> a >> v;
mp[a] += v;
}
vector<P>V;
for (P i : mp)V.push_back(i);
stable_sort(V.begin(), V.end(), [](P a, P b) {return a.second > b.second; });
cout << V[0].first << ' ' << V[0].second << endl;
} | CPP |
p00095 Surf Smelt Fishing Contest | A smelt fishing tournament was held at Lake Hibara. The winner is the one who wins the most smelt.
Create a program that reads the list of participant numbers and the number of fish caught and outputs the number of winners and the number of fish caught. If there are multiple winners, output the one with the lowest participant number.
input
The input is given in the following format.
n
a1 v1
a2 v2
::
an vn
n (1 ≤ n ≤ 20) represents the number of participants and ai represents the participant number. Participant numbers are different integers between 1 and n. vi (0 ≤ vi ≤ 100) is the number of animals acquired by the participant ai.
output
Output the winner's participant number and the number of fish caught on one line separated by blanks.
Example
Input
6
1 14
2 25
3 42
4 11
5 40
6 37
Output
3 42 | 7 | 0 | #include <iostream>
#include <vector>
#include <algorithm>
using namespace std;
int main() {
vector< pair< long long int, long long int > > cnt;
long long int n;
cin >> n;
for ( long long int i = 0; i < n; i++ ) {
long long int in0, in1;
cin >> in0 >> in1;
cnt.push_back( make_pair( -in1, in0 ) );
}
sort( cnt.begin(), cnt.end() );
cout << cnt[0].second << " " << -cnt[0].first << endl;
return 0;
} | CPP |
p00095 Surf Smelt Fishing Contest | A smelt fishing tournament was held at Lake Hibara. The winner is the one who wins the most smelt.
Create a program that reads the list of participant numbers and the number of fish caught and outputs the number of winners and the number of fish caught. If there are multiple winners, output the one with the lowest participant number.
input
The input is given in the following format.
n
a1 v1
a2 v2
::
an vn
n (1 ≤ n ≤ 20) represents the number of participants and ai represents the participant number. Participant numbers are different integers between 1 and n. vi (0 ≤ vi ≤ 100) is the number of animals acquired by the participant ai.
output
Output the winner's participant number and the number of fish caught on one line separated by blanks.
Example
Input
6
1 14
2 25
3 42
4 11
5 40
6 37
Output
3 42 | 7 | 0 | #include <iostream>
#include <vector>
#include <algorithm>
using namespace std;
typedef pair<int, int> p;
void solve()
{
int n;
cin >> n;
vector<p> list(n);
for(int i = 0; i < n; ++i)
{
cin >> list[i].second >> list[i].first;
}
sort(list.begin(), list.end());
int max_point = list[n - 1].first;
int min_num = 99999;
for(int i = 0; i < n; ++i)
{
if(max_point == list[i].first)
{
if(min_num > list[i].second)
{
min_num = list[i].second;
}
}
}
cout << min_num << " " << max_point << endl;
}
int main()
{
solve();
return(0);
} | CPP |
p00095 Surf Smelt Fishing Contest | A smelt fishing tournament was held at Lake Hibara. The winner is the one who wins the most smelt.
Create a program that reads the list of participant numbers and the number of fish caught and outputs the number of winners and the number of fish caught. If there are multiple winners, output the one with the lowest participant number.
input
The input is given in the following format.
n
a1 v1
a2 v2
::
an vn
n (1 ≤ n ≤ 20) represents the number of participants and ai represents the participant number. Participant numbers are different integers between 1 and n. vi (0 ≤ vi ≤ 100) is the number of animals acquired by the participant ai.
output
Output the winner's participant number and the number of fish caught on one line separated by blanks.
Example
Input
6
1 14
2 25
3 42
4 11
5 40
6 37
Output
3 42 | 7 | 0 | #include <iostream>
#include <algorithm>
using namespace std;
int main(){
for(int n;cin>>n;){
pair<int,int> p[20];
for(int i=0;i<n;i++) cin>>p[i].second>>p[i].first,p[i].first*=-1;
sort(p,p+n);
cout<<p[0].second<<' '<<p[0].first*-1<<endl;
}
return 0;
} | CPP |
p00095 Surf Smelt Fishing Contest | A smelt fishing tournament was held at Lake Hibara. The winner is the one who wins the most smelt.
Create a program that reads the list of participant numbers and the number of fish caught and outputs the number of winners and the number of fish caught. If there are multiple winners, output the one with the lowest participant number.
input
The input is given in the following format.
n
a1 v1
a2 v2
::
an vn
n (1 ≤ n ≤ 20) represents the number of participants and ai represents the participant number. Participant numbers are different integers between 1 and n. vi (0 ≤ vi ≤ 100) is the number of animals acquired by the participant ai.
output
Output the winner's participant number and the number of fish caught on one line separated by blanks.
Example
Input
6
1 14
2 25
3 42
4 11
5 40
6 37
Output
3 42 | 7 | 0 | a=[]
for i in range(int(input())):
a.append(list(map(int,input().split(" "))))
a.sort(reverse=True)
a.sort(key=lambda x:x[1])
print(*a[-1])
| PYTHON3 |
p00095 Surf Smelt Fishing Contest | A smelt fishing tournament was held at Lake Hibara. The winner is the one who wins the most smelt.
Create a program that reads the list of participant numbers and the number of fish caught and outputs the number of winners and the number of fish caught. If there are multiple winners, output the one with the lowest participant number.
input
The input is given in the following format.
n
a1 v1
a2 v2
::
an vn
n (1 ≤ n ≤ 20) represents the number of participants and ai represents the participant number. Participant numbers are different integers between 1 and n. vi (0 ≤ vi ≤ 100) is the number of animals acquired by the participant ai.
output
Output the winner's participant number and the number of fish caught on one line separated by blanks.
Example
Input
6
1 14
2 25
3 42
4 11
5 40
6 37
Output
3 42 | 7 | 0 | #include<cstdio>
using namespace std;
int min(int a,int b){return(a < b)?a:b;}
int main(){
int n;
scanf("%d",&n);
int num = 99999,fish = 0;
for(int i = 0; i < n; i++){
int x,y;
scanf("%d%d",&x,&y);
if(fish <= y){
if(fish == y)num = min(num,x);
else num = x;
fish = y;
}
}
printf("%d %d\n",num,fish);
return 0;
} | CPP |
p00095 Surf Smelt Fishing Contest | A smelt fishing tournament was held at Lake Hibara. The winner is the one who wins the most smelt.
Create a program that reads the list of participant numbers and the number of fish caught and outputs the number of winners and the number of fish caught. If there are multiple winners, output the one with the lowest participant number.
input
The input is given in the following format.
n
a1 v1
a2 v2
::
an vn
n (1 ≤ n ≤ 20) represents the number of participants and ai represents the participant number. Participant numbers are different integers between 1 and n. vi (0 ≤ vi ≤ 100) is the number of animals acquired by the participant ai.
output
Output the winner's participant number and the number of fish caught on one line separated by blanks.
Example
Input
6
1 14
2 25
3 42
4 11
5 40
6 37
Output
3 42 | 7 | 0 | #include <iostream>
using namespace std;
int info[22];
int main()
{
int n, a, v;
int max_idx = 0;
cin >> n;
info[max_idx] = -10;
for (int i = 0; i < n; i++) {
cin >> a >> v;
info[a] = v;
}
for (int i = 1; i <= n; i++)
if (info[max_idx] < info[i])
max_idx = i;
cout << max_idx << " " << info[max_idx] << endl;
return 0;
} | CPP |
p00095 Surf Smelt Fishing Contest | A smelt fishing tournament was held at Lake Hibara. The winner is the one who wins the most smelt.
Create a program that reads the list of participant numbers and the number of fish caught and outputs the number of winners and the number of fish caught. If there are multiple winners, output the one with the lowest participant number.
input
The input is given in the following format.
n
a1 v1
a2 v2
::
an vn
n (1 ≤ n ≤ 20) represents the number of participants and ai represents the participant number. Participant numbers are different integers between 1 and n. vi (0 ≤ vi ≤ 100) is the number of animals acquired by the participant ai.
output
Output the winner's participant number and the number of fish caught on one line separated by blanks.
Example
Input
6
1 14
2 25
3 42
4 11
5 40
6 37
Output
3 42 | 7 | 0 | #include <bits/stdc++.h>
using namespace std;
typedef long long ll;
int main(void){
// Your code here!
ll n;
cin>>n;
ll a[n],b[n];
vector<pair<ll, ll> > ab(n);
for(ll i=0;i<n;i++)cin>>a[i]>>b[i];
for(int i=0;i<n;i++){
ab[i] = make_pair(b[i],a[i]);
}
sort(ab.begin(),ab.end());
int mi=101;
for(int i=0;i<n;i++){
if(ab[i].first==ab[n-1].first){
if(mi>ab[i].second)mi=ab[i].second;
}
}
cout<<mi<<" "<<ab[n-1].first<<endl;
}
| CPP |
p00095 Surf Smelt Fishing Contest | A smelt fishing tournament was held at Lake Hibara. The winner is the one who wins the most smelt.
Create a program that reads the list of participant numbers and the number of fish caught and outputs the number of winners and the number of fish caught. If there are multiple winners, output the one with the lowest participant number.
input
The input is given in the following format.
n
a1 v1
a2 v2
::
an vn
n (1 ≤ n ≤ 20) represents the number of participants and ai represents the participant number. Participant numbers are different integers between 1 and n. vi (0 ≤ vi ≤ 100) is the number of animals acquired by the participant ai.
output
Output the winner's participant number and the number of fish caught on one line separated by blanks.
Example
Input
6
1 14
2 25
3 42
4 11
5 40
6 37
Output
3 42 | 7 | 0 | import java.util.Scanner;
public class Main {
public static void main(String[] args){
Scanner sc=new Scanner(System.in);
int n=sc.nextInt();
int[] a=new int[n];
int[] v=new int[n];
for(int i=0;i<n;i++){
a[i]=sc.nextInt();
v[i]=sc.nextInt();
}
for(int i=0;i<n-1;i++){
for(int j=n-1;j>i;j--){
if(a[j-1]>a[j]){
int box=v[j-1];
v[j-1]=v[j];
v[j]=box;
box=a[j];
a[j]=a[j-1];
a[j-1]=box;
}
}
}
int max=v[0];
int maxPtr=a[0];
for(int i=1;i<n;i++){
if(v[i]>max){
max=v[i];
maxPtr=a[i];
}
}
System.out.println(maxPtr+" "+max);
}
} | JAVA |
p00095 Surf Smelt Fishing Contest | A smelt fishing tournament was held at Lake Hibara. The winner is the one who wins the most smelt.
Create a program that reads the list of participant numbers and the number of fish caught and outputs the number of winners and the number of fish caught. If there are multiple winners, output the one with the lowest participant number.
input
The input is given in the following format.
n
a1 v1
a2 v2
::
an vn
n (1 ≤ n ≤ 20) represents the number of participants and ai represents the participant number. Participant numbers are different integers between 1 and n. vi (0 ≤ vi ≤ 100) is the number of animals acquired by the participant ai.
output
Output the winner's participant number and the number of fish caught on one line separated by blanks.
Example
Input
6
1 14
2 25
3 42
4 11
5 40
6 37
Output
3 42 | 7 | 0 | n = int(input())
av = [None] * n
for i in range(n):
a, v = map(int, input().split())
av[i] = [a, v]
av.sort()
ans = av[0][0]
for a, v in av:
if av[ans - 1][1] < v:
ans = a
print(ans, av[ans - 1][1])
| PYTHON3 |
p00095 Surf Smelt Fishing Contest | A smelt fishing tournament was held at Lake Hibara. The winner is the one who wins the most smelt.
Create a program that reads the list of participant numbers and the number of fish caught and outputs the number of winners and the number of fish caught. If there are multiple winners, output the one with the lowest participant number.
input
The input is given in the following format.
n
a1 v1
a2 v2
::
an vn
n (1 ≤ n ≤ 20) represents the number of participants and ai represents the participant number. Participant numbers are different integers between 1 and n. vi (0 ≤ vi ≤ 100) is the number of animals acquired by the participant ai.
output
Output the winner's participant number and the number of fish caught on one line separated by blanks.
Example
Input
6
1 14
2 25
3 42
4 11
5 40
6 37
Output
3 42 | 7 | 0 | #include <bits/stdc++.h>
using namespace std;
typedef pair<int,int> P;
int main(){
int n;
cin>>n;
P a[101];
for(int i=0;i<n;i++) cin>>a[i].second>>a[i].first,a[i].second*=-1;
sort(a,a+n,greater<P>());
cout << -a[0].second<<" "<<a[0].first<<endl;
return 0;
} | CPP |
p00095 Surf Smelt Fishing Contest | A smelt fishing tournament was held at Lake Hibara. The winner is the one who wins the most smelt.
Create a program that reads the list of participant numbers and the number of fish caught and outputs the number of winners and the number of fish caught. If there are multiple winners, output the one with the lowest participant number.
input
The input is given in the following format.
n
a1 v1
a2 v2
::
an vn
n (1 ≤ n ≤ 20) represents the number of participants and ai represents the participant number. Participant numbers are different integers between 1 and n. vi (0 ≤ vi ≤ 100) is the number of animals acquired by the participant ai.
output
Output the winner's participant number and the number of fish caught on one line separated by blanks.
Example
Input
6
1 14
2 25
3 42
4 11
5 40
6 37
Output
3 42 | 7 | 0 | n = int(raw_input())
lis = []
num = {}
for i in xrange(n):
a,b = map(int,raw_input().split())
num[a] = b
lis.append(b)
lis.sort(reverse = True)
list = []
for var in num:
if lis[0] == num[var]:
list.append(var)
list.sort()
print list[0],lis[0] | PYTHON |
p00095 Surf Smelt Fishing Contest | A smelt fishing tournament was held at Lake Hibara. The winner is the one who wins the most smelt.
Create a program that reads the list of participant numbers and the number of fish caught and outputs the number of winners and the number of fish caught. If there are multiple winners, output the one with the lowest participant number.
input
The input is given in the following format.
n
a1 v1
a2 v2
::
an vn
n (1 ≤ n ≤ 20) represents the number of participants and ai represents the participant number. Participant numbers are different integers between 1 and n. vi (0 ≤ vi ≤ 100) is the number of animals acquired by the participant ai.
output
Output the winner's participant number and the number of fish caught on one line separated by blanks.
Example
Input
6
1 14
2 25
3 42
4 11
5 40
6 37
Output
3 42 | 7 | 0 | #include<iostream>
using namespace std;
int main(){
int n,m=1;cin >> n;
int d[21]={};
int a,v;
while(n--){
cin >> a >> v;d[a]=v;
if(d[m]==d[a]&&a<m)m=a;
if(d[m]<d[a])m=a;
}
cout << m << " " << d[m] << endl;
} | CPP |
p00095 Surf Smelt Fishing Contest | A smelt fishing tournament was held at Lake Hibara. The winner is the one who wins the most smelt.
Create a program that reads the list of participant numbers and the number of fish caught and outputs the number of winners and the number of fish caught. If there are multiple winners, output the one with the lowest participant number.
input
The input is given in the following format.
n
a1 v1
a2 v2
::
an vn
n (1 ≤ n ≤ 20) represents the number of participants and ai represents the participant number. Participant numbers are different integers between 1 and n. vi (0 ≤ vi ≤ 100) is the number of animals acquired by the participant ai.
output
Output the winner's participant number and the number of fish caught on one line separated by blanks.
Example
Input
6
1 14
2 25
3 42
4 11
5 40
6 37
Output
3 42 | 7 | 0 | import java.util.Scanner;
class Main
{
public static void main(String[] args)
{
Scanner sc = new Scanner(System.in);
int n = sc.nextInt();
int max = -1;
int ind = -1;
for(int i = 0; i < n; ++i){
int d = sc.nextInt();
int c = sc.nextInt();
if( c > max ){
max = c;
ind = d;
}else if( c == max ){
if( ind > d ) ind = d;
}
}
System.out.println( ind + " " + max );
}
} | JAVA |
p00095 Surf Smelt Fishing Contest | A smelt fishing tournament was held at Lake Hibara. The winner is the one who wins the most smelt.
Create a program that reads the list of participant numbers and the number of fish caught and outputs the number of winners and the number of fish caught. If there are multiple winners, output the one with the lowest participant number.
input
The input is given in the following format.
n
a1 v1
a2 v2
::
an vn
n (1 ≤ n ≤ 20) represents the number of participants and ai represents the participant number. Participant numbers are different integers between 1 and n. vi (0 ≤ vi ≤ 100) is the number of animals acquired by the participant ai.
output
Output the winner's participant number and the number of fish caught on one line separated by blanks.
Example
Input
6
1 14
2 25
3 42
4 11
5 40
6 37
Output
3 42 | 7 | 0 | #include<vector>
#include<iostream>
#include<algorithm>
using namespace std;
int main(){
int N,x,y,ans1,ans2=-1;
vector <int> num;
cin >> N;
while(N--){
cin >> x >> y;
if(y>ans2){
num.clear();
num.push_back(x);
ans2 = y;
}
else if(y==ans2){
num.push_back(x);
}
}
sort(num.begin(),num.end());
cout << num[0] << ' ' << ans2 << endl;
return 0;
}
| CPP |
p00095 Surf Smelt Fishing Contest | A smelt fishing tournament was held at Lake Hibara. The winner is the one who wins the most smelt.
Create a program that reads the list of participant numbers and the number of fish caught and outputs the number of winners and the number of fish caught. If there are multiple winners, output the one with the lowest participant number.
input
The input is given in the following format.
n
a1 v1
a2 v2
::
an vn
n (1 ≤ n ≤ 20) represents the number of participants and ai represents the participant number. Participant numbers are different integers between 1 and n. vi (0 ≤ vi ≤ 100) is the number of animals acquired by the participant ai.
output
Output the winner's participant number and the number of fish caught on one line separated by blanks.
Example
Input
6
1 14
2 25
3 42
4 11
5 40
6 37
Output
3 42 | 7 | 0 | #include<bits/stdc++.h>
using namespace std;
#define rep(i,a) for(int i = 0; i < (a); i++)
#define reps(i, a, b) for(int i = (a); i < (b); i++)
#define INF 1e9
typedef vector<int> vi;
typedef vector<vi> vii;
typedef pair<int, int> pii;
int main() {
int n;
vector<pii> v;
cin >> n;
rep(i, n) {
int ind, a;
cin >> ind >> a;
v.push_back(make_pair(ind,a));
}
sort(v.begin(), v.end(), [](pii a,pii b) -> bool {
if(a.second == b.second) return a.first < b.first;
return a.second > b.second;
});
cout << v[0].first << " " << v[0].second << endl;
return 0;
} | CPP |
p00095 Surf Smelt Fishing Contest | A smelt fishing tournament was held at Lake Hibara. The winner is the one who wins the most smelt.
Create a program that reads the list of participant numbers and the number of fish caught and outputs the number of winners and the number of fish caught. If there are multiple winners, output the one with the lowest participant number.
input
The input is given in the following format.
n
a1 v1
a2 v2
::
an vn
n (1 ≤ n ≤ 20) represents the number of participants and ai represents the participant number. Participant numbers are different integers between 1 and n. vi (0 ≤ vi ≤ 100) is the number of animals acquired by the participant ai.
output
Output the winner's participant number and the number of fish caught on one line separated by blanks.
Example
Input
6
1 14
2 25
3 42
4 11
5 40
6 37
Output
3 42 | 7 | 0 | #include <bits/stdc++.h>
using namespace std;
int main(void){
int n,winner,max=0,a,v;
cin>>n;
for (int i=0;i<n;i++) {
cin>>a>>v;
if (v>max) {
winner=a;
max=v;
} else if (v==max) {
if (a<winner) {
winner=a;
}
}
}
cout<<winner<<" "<<max<<endl;
}
| CPP |
p00095 Surf Smelt Fishing Contest | A smelt fishing tournament was held at Lake Hibara. The winner is the one who wins the most smelt.
Create a program that reads the list of participant numbers and the number of fish caught and outputs the number of winners and the number of fish caught. If there are multiple winners, output the one with the lowest participant number.
input
The input is given in the following format.
n
a1 v1
a2 v2
::
an vn
n (1 ≤ n ≤ 20) represents the number of participants and ai represents the participant number. Participant numbers are different integers between 1 and n. vi (0 ≤ vi ≤ 100) is the number of animals acquired by the participant ai.
output
Output the winner's participant number and the number of fish caught on one line separated by blanks.
Example
Input
6
1 14
2 25
3 42
4 11
5 40
6 37
Output
3 42 | 7 | 0 | import java.util.Scanner;
public class Main{
public static void main(String args[]){
new Main().mainrun();
}
private Scanner scan;
private int n,id,value;
private void mainrun() {
scan = new Scanner(System.in);
n = scan.nextInt();
id = -1;
value = Integer.MIN_VALUE;
for(int i = 0;i < n;i++) {
int a = scan.nextInt();
int v = scan.nextInt();
if( v > value || (v == value && a < id)) {
id = a;
value = v;
}
}
System.out.println(id + " " + value);
scan.close();
}
}
class Data{
public Data(int id) {
this.id = id;
value = 0;
}
int id;
int value;
}
| JAVA |
p00095 Surf Smelt Fishing Contest | A smelt fishing tournament was held at Lake Hibara. The winner is the one who wins the most smelt.
Create a program that reads the list of participant numbers and the number of fish caught and outputs the number of winners and the number of fish caught. If there are multiple winners, output the one with the lowest participant number.
input
The input is given in the following format.
n
a1 v1
a2 v2
::
an vn
n (1 ≤ n ≤ 20) represents the number of participants and ai represents the participant number. Participant numbers are different integers between 1 and n. vi (0 ≤ vi ≤ 100) is the number of animals acquired by the participant ai.
output
Output the winner's participant number and the number of fish caught on one line separated by blanks.
Example
Input
6
1 14
2 25
3 42
4 11
5 40
6 37
Output
3 42 | 7 | 0 | #include<iostream>
#include<string>
#include<vector>
#include<cstdio>
#include<sstream>
#include<algorithm>
#include<cmath>
#include<map>
#include<functional>
using namespace std;
int stoi(string x){stringstream ss;ss<<x;int tmp;ss>>tmp;return tmp;}
string itos(int x){stringstream ss;ss<<x;return ss.str();}
int main(){
int ta[10000]={0},n;
cin>>n;
int ans=0,ansi=10000;
for(int i=0;i<n;i++){
int a,b;
cin>>a>>b;
if(ans<b)ans=b,ansi=a;
if(ans==b)ansi=min(ansi,a);
}
cout<<ansi<<" "<<ans<<endl;
return 0;
} | CPP |
p00095 Surf Smelt Fishing Contest | A smelt fishing tournament was held at Lake Hibara. The winner is the one who wins the most smelt.
Create a program that reads the list of participant numbers and the number of fish caught and outputs the number of winners and the number of fish caught. If there are multiple winners, output the one with the lowest participant number.
input
The input is given in the following format.
n
a1 v1
a2 v2
::
an vn
n (1 ≤ n ≤ 20) represents the number of participants and ai represents the participant number. Participant numbers are different integers between 1 and n. vi (0 ≤ vi ≤ 100) is the number of animals acquired by the participant ai.
output
Output the winner's participant number and the number of fish caught on one line separated by blanks.
Example
Input
6
1 14
2 25
3 42
4 11
5 40
6 37
Output
3 42 | 7 | 0 | #include <iostream>
using namespace std;
int main(){
int n;
while(cin >> n){
int minA, maxV = -1;
for(int i = 0; i < n; i++){
int a, v;
cin >> a >> v;
if(maxV < v || maxV == v && minA > a){
minA = a;
maxV = v;
}
}
cout << minA << " " << maxV << endl;
}
} | CPP |
p00095 Surf Smelt Fishing Contest | A smelt fishing tournament was held at Lake Hibara. The winner is the one who wins the most smelt.
Create a program that reads the list of participant numbers and the number of fish caught and outputs the number of winners and the number of fish caught. If there are multiple winners, output the one with the lowest participant number.
input
The input is given in the following format.
n
a1 v1
a2 v2
::
an vn
n (1 ≤ n ≤ 20) represents the number of participants and ai represents the participant number. Participant numbers are different integers between 1 and n. vi (0 ≤ vi ≤ 100) is the number of animals acquired by the participant ai.
output
Output the winner's participant number and the number of fish caught on one line separated by blanks.
Example
Input
6
1 14
2 25
3 42
4 11
5 40
6 37
Output
3 42 | 7 | 0 | N = int(input())
n, a = -1, 0
for x in sorted([list(map(int, reversed(input().split()))) for i in range(N)], reverse=True):
if x[0] < n:
break
n, a = x
print(a, n) | PYTHON3 |
p00095 Surf Smelt Fishing Contest | A smelt fishing tournament was held at Lake Hibara. The winner is the one who wins the most smelt.
Create a program that reads the list of participant numbers and the number of fish caught and outputs the number of winners and the number of fish caught. If there are multiple winners, output the one with the lowest participant number.
input
The input is given in the following format.
n
a1 v1
a2 v2
::
an vn
n (1 ≤ n ≤ 20) represents the number of participants and ai represents the participant number. Participant numbers are different integers between 1 and n. vi (0 ≤ vi ≤ 100) is the number of animals acquired by the participant ai.
output
Output the winner's participant number and the number of fish caught on one line separated by blanks.
Example
Input
6
1 14
2 25
3 42
4 11
5 40
6 37
Output
3 42 | 7 | 0 | #include <iostream>
#include <algorithm>
#include <vector>
#include <cstdio>
using namespace std;
int main(void)
{
int n;
int a, v;
vector < pair <int, int> > vi;
cin >> n;
while (n--){
cin >> a >> v;
vi.push_back(make_pair(v, a));
}
sort(vi.rbegin(), vi.rend());
int ret[2] = {0}, ma = vi[0].first;
for (int i = 0; i < vi.size(); i++){
if (ma == vi[i].first){
ret[0] = vi[i].first;
ret[1] = vi[i].second;
}
else {
break;
}
}
cout << ret[1] << " " << ret[0] << endl;
return 0;
} | CPP |
p00095 Surf Smelt Fishing Contest | A smelt fishing tournament was held at Lake Hibara. The winner is the one who wins the most smelt.
Create a program that reads the list of participant numbers and the number of fish caught and outputs the number of winners and the number of fish caught. If there are multiple winners, output the one with the lowest participant number.
input
The input is given in the following format.
n
a1 v1
a2 v2
::
an vn
n (1 ≤ n ≤ 20) represents the number of participants and ai represents the participant number. Participant numbers are different integers between 1 and n. vi (0 ≤ vi ≤ 100) is the number of animals acquired by the participant ai.
output
Output the winner's participant number and the number of fish caught on one line separated by blanks.
Example
Input
6
1 14
2 25
3 42
4 11
5 40
6 37
Output
3 42 | 7 | 0 | n = int(input())
d = {t[0]: t[1] for t in [list(map(int, input().split())) for _ in range(n)]}
print(*max(d.items(), key=lambda x: x[1])) | PYTHON3 |
p00095 Surf Smelt Fishing Contest | A smelt fishing tournament was held at Lake Hibara. The winner is the one who wins the most smelt.
Create a program that reads the list of participant numbers and the number of fish caught and outputs the number of winners and the number of fish caught. If there are multiple winners, output the one with the lowest participant number.
input
The input is given in the following format.
n
a1 v1
a2 v2
::
an vn
n (1 ≤ n ≤ 20) represents the number of participants and ai represents the participant number. Participant numbers are different integers between 1 and n. vi (0 ≤ vi ≤ 100) is the number of animals acquired by the participant ai.
output
Output the winner's participant number and the number of fish caught on one line separated by blanks.
Example
Input
6
1 14
2 25
3 42
4 11
5 40
6 37
Output
3 42 | 7 | 0 | #include <stdio.h>
#include <cmath>
#include <algorithm>
using namespace std;
int main(){
int n,tmp_id,max_id,max=-1,tmp;
scanf("%d",&n);
for(int i=0; i < n; i++){
scanf("%d %d",&tmp_id,&tmp);
if(tmp > max){
max = tmp;
max_id = tmp_id;
}else if(tmp == max){
if(max_id > tmp_id){
max_id = tmp_id;
}
}
}
printf("%d %d\n",max_id,max);
return 0;
} | CPP |
p00095 Surf Smelt Fishing Contest | A smelt fishing tournament was held at Lake Hibara. The winner is the one who wins the most smelt.
Create a program that reads the list of participant numbers and the number of fish caught and outputs the number of winners and the number of fish caught. If there are multiple winners, output the one with the lowest participant number.
input
The input is given in the following format.
n
a1 v1
a2 v2
::
an vn
n (1 ≤ n ≤ 20) represents the number of participants and ai represents the participant number. Participant numbers are different integers between 1 and n. vi (0 ≤ vi ≤ 100) is the number of animals acquired by the participant ai.
output
Output the winner's participant number and the number of fish caught on one line separated by blanks.
Example
Input
6
1 14
2 25
3 42
4 11
5 40
6 37
Output
3 42 | 7 | 0 | a = [0] * 20
v = [0] * 20
a_v = []
for i in range(int(raw_input())):
a[i],v[i] = map(int, raw_input().split())
a_v.append([a[i], v[i]])
a_v.sort()
ans2 = max(v)
for i in a_v:
if i[1] == ans2:
ans1 = i[0]
break
print "{} {}".format(ans1, ans2) | PYTHON |
p00095 Surf Smelt Fishing Contest | A smelt fishing tournament was held at Lake Hibara. The winner is the one who wins the most smelt.
Create a program that reads the list of participant numbers and the number of fish caught and outputs the number of winners and the number of fish caught. If there are multiple winners, output the one with the lowest participant number.
input
The input is given in the following format.
n
a1 v1
a2 v2
::
an vn
n (1 ≤ n ≤ 20) represents the number of participants and ai represents the participant number. Participant numbers are different integers between 1 and n. vi (0 ≤ vi ≤ 100) is the number of animals acquired by the participant ai.
output
Output the winner's participant number and the number of fish caught on one line separated by blanks.
Example
Input
6
1 14
2 25
3 42
4 11
5 40
6 37
Output
3 42 | 7 | 0 | lis = []
for i in xrange(input()):
lis.append(map(int,raw_input().split()))
print " ".join(map(str,sorted(lis,cmp=lambda a,b:cmp(a[0],b[0]) if a[1] == b[1] else cmp(b[1],a[1]))[0])) | PYTHON |
p00095 Surf Smelt Fishing Contest | A smelt fishing tournament was held at Lake Hibara. The winner is the one who wins the most smelt.
Create a program that reads the list of participant numbers and the number of fish caught and outputs the number of winners and the number of fish caught. If there are multiple winners, output the one with the lowest participant number.
input
The input is given in the following format.
n
a1 v1
a2 v2
::
an vn
n (1 ≤ n ≤ 20) represents the number of participants and ai represents the participant number. Participant numbers are different integers between 1 and n. vi (0 ≤ vi ≤ 100) is the number of animals acquired by the participant ai.
output
Output the winner's participant number and the number of fish caught on one line separated by blanks.
Example
Input
6
1 14
2 25
3 42
4 11
5 40
6 37
Output
3 42 | 7 | 0 | #include<iostream>
#include<cstdio>
#include<algorithm>
#include<string>
#include<cmath>
using namespace std;
int a,b,ma,ans,n;
int main(){
cin>>n;
cin>>a>>b;
ma=b,ans=a;
for(int i=1;i<n;i++){
cin>>a>>b;
if(ma<b){
ans=a;
ma=b;
}else if(ma==b&&ans>a)ans=a;
}
cout<<ans<<" "<<ma<<endl;
return 0;
} | CPP |
p00095 Surf Smelt Fishing Contest | A smelt fishing tournament was held at Lake Hibara. The winner is the one who wins the most smelt.
Create a program that reads the list of participant numbers and the number of fish caught and outputs the number of winners and the number of fish caught. If there are multiple winners, output the one with the lowest participant number.
input
The input is given in the following format.
n
a1 v1
a2 v2
::
an vn
n (1 ≤ n ≤ 20) represents the number of participants and ai represents the participant number. Participant numbers are different integers between 1 and n. vi (0 ≤ vi ≤ 100) is the number of animals acquired by the participant ai.
output
Output the winner's participant number and the number of fish caught on one line separated by blanks.
Example
Input
6
1 14
2 25
3 42
4 11
5 40
6 37
Output
3 42 | 7 | 0 | #include <algorithm>
#include <iomanip>
#include <iostream>
#include <vector>
using namespace std;
typedef long long ll;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef pair<int, int> pii;
#define reps(i,f,n) for(int i=f; i<int(n); ++i)
#define rep(i,n) reps(i,0,n)
int main()
{
int n;
cin >> n;
pii ans(-1, -1);
rep(i, n){
pii t;
cin >> t.second >> t.first;
t.second *= -1;
ans = max(ans, t);
}
cout << -ans.second << ' ' << ans.first << endl;
} | CPP |
p00095 Surf Smelt Fishing Contest | A smelt fishing tournament was held at Lake Hibara. The winner is the one who wins the most smelt.
Create a program that reads the list of participant numbers and the number of fish caught and outputs the number of winners and the number of fish caught. If there are multiple winners, output the one with the lowest participant number.
input
The input is given in the following format.
n
a1 v1
a2 v2
::
an vn
n (1 ≤ n ≤ 20) represents the number of participants and ai represents the participant number. Participant numbers are different integers between 1 and n. vi (0 ≤ vi ≤ 100) is the number of animals acquired by the participant ai.
output
Output the winner's participant number and the number of fish caught on one line separated by blanks.
Example
Input
6
1 14
2 25
3 42
4 11
5 40
6 37
Output
3 42 | 7 | 0 | #include <bits/stdc++.h>
using namespace std;
typedef pair<int, int> pii;
vector<pii> v;
int main() {
int n;
cin >> n;
for (int i = 0; i < n; i++) {
int a, b;
scanf("%d %d", &a, &b);
v.push_back(pii(-b, a));
}
sort(v.begin(), v.end());
cout << v[0].second << " " << -v[0].first << endl;
return 0;
}
| CPP |
p00095 Surf Smelt Fishing Contest | A smelt fishing tournament was held at Lake Hibara. The winner is the one who wins the most smelt.
Create a program that reads the list of participant numbers and the number of fish caught and outputs the number of winners and the number of fish caught. If there are multiple winners, output the one with the lowest participant number.
input
The input is given in the following format.
n
a1 v1
a2 v2
::
an vn
n (1 ≤ n ≤ 20) represents the number of participants and ai represents the participant number. Participant numbers are different integers between 1 and n. vi (0 ≤ vi ≤ 100) is the number of animals acquired by the participant ai.
output
Output the winner's participant number and the number of fish caught on one line separated by blanks.
Example
Input
6
1 14
2 25
3 42
4 11
5 40
6 37
Output
3 42 | 7 | 0 | import java.util.Scanner;
class Main {
Scanner scan = new Scanner(System.in);
public static void main(String args[]){
Main app = new Main();
while(app.scan.hasNext()){
int n = Integer.parseInt(app.scan.nextLine());
int[][] entrant = new int[n][2];
app.input(n, entrant);
int index = app.max(n,entrant);
System.out.println(entrant[index][0]+" "+entrant[index][1]);
}
}
public void input(int n,int[][] e){
String[] splitLine;
for(int i=0;i<n;i++){
splitLine = scan.nextLine().split(" ");
e[i][0] = Integer.parseInt(splitLine[0]);
e[i][1] = Integer.parseInt(splitLine[1]);
}
}
public int max(int n,int[][] e){
int max=0;
int index = 0;
for(int i=0;i<n;i++){
if(e[i][1] > max){
max = e[i][1];
index = i;
}
}
for(int i=0;i<n;i++){
if(e[i][1] == max){
if(e[i][0] < e[index][0]){
index = i;
}
}
}
return index;
}
} | JAVA |
p00095 Surf Smelt Fishing Contest | A smelt fishing tournament was held at Lake Hibara. The winner is the one who wins the most smelt.
Create a program that reads the list of participant numbers and the number of fish caught and outputs the number of winners and the number of fish caught. If there are multiple winners, output the one with the lowest participant number.
input
The input is given in the following format.
n
a1 v1
a2 v2
::
an vn
n (1 ≤ n ≤ 20) represents the number of participants and ai represents the participant number. Participant numbers are different integers between 1 and n. vi (0 ≤ vi ≤ 100) is the number of animals acquired by the participant ai.
output
Output the winner's participant number and the number of fish caught on one line separated by blanks.
Example
Input
6
1 14
2 25
3 42
4 11
5 40
6 37
Output
3 42 | 7 | 0 | #include "bits/stdc++.h"
using namespace std;
typedef long long ll;
int main(){
int n;
cin >> n;
int A = 0, V = -1;
for(int i = 0; i < n; i++){
int a, v;
cin >> a >> v;
if(v > V){
A = a;
V = v;
}
if(v == V && a < A){
A = a;
V = v;
}
}
cout << A << " " << V << endl;
return 0;
}
| CPP |
p00095 Surf Smelt Fishing Contest | A smelt fishing tournament was held at Lake Hibara. The winner is the one who wins the most smelt.
Create a program that reads the list of participant numbers and the number of fish caught and outputs the number of winners and the number of fish caught. If there are multiple winners, output the one with the lowest participant number.
input
The input is given in the following format.
n
a1 v1
a2 v2
::
an vn
n (1 ≤ n ≤ 20) represents the number of participants and ai represents the participant number. Participant numbers are different integers between 1 and n. vi (0 ≤ vi ≤ 100) is the number of animals acquired by the participant ai.
output
Output the winner's participant number and the number of fish caught on one line separated by blanks.
Example
Input
6
1 14
2 25
3 42
4 11
5 40
6 37
Output
3 42 | 7 | 0 | print(*sorted([list(map(int, input().split())) for _ in [0]*int(input())], key=lambda x:(-x[1],x[0]))[0])
| PYTHON3 |
p00095 Surf Smelt Fishing Contest | A smelt fishing tournament was held at Lake Hibara. The winner is the one who wins the most smelt.
Create a program that reads the list of participant numbers and the number of fish caught and outputs the number of winners and the number of fish caught. If there are multiple winners, output the one with the lowest participant number.
input
The input is given in the following format.
n
a1 v1
a2 v2
::
an vn
n (1 ≤ n ≤ 20) represents the number of participants and ai represents the participant number. Participant numbers are different integers between 1 and n. vi (0 ≤ vi ≤ 100) is the number of animals acquired by the participant ai.
output
Output the winner's participant number and the number of fish caught on one line separated by blanks.
Example
Input
6
1 14
2 25
3 42
4 11
5 40
6 37
Output
3 42 | 7 | 0 | #include <algorithm>
#include <iostream>
#include <utility>
#include <vector>
using namespace std;
int main(){
int n;
cin >> n;
vector<pair<int,int> > p(n, pair<int,int>(0,0));
for (int i = 0; i < n; i++){
cin >> p[i].second >> p[i].first;
p[i].second = -p[i].second;
}
sort(p.begin(), p.end(), greater<pair<int,int> >());
cout << (-p[0].second) << ' ' << p[0].first << endl;
} | CPP |
p00095 Surf Smelt Fishing Contest | A smelt fishing tournament was held at Lake Hibara. The winner is the one who wins the most smelt.
Create a program that reads the list of participant numbers and the number of fish caught and outputs the number of winners and the number of fish caught. If there are multiple winners, output the one with the lowest participant number.
input
The input is given in the following format.
n
a1 v1
a2 v2
::
an vn
n (1 ≤ n ≤ 20) represents the number of participants and ai represents the participant number. Participant numbers are different integers between 1 and n. vi (0 ≤ vi ≤ 100) is the number of animals acquired by the participant ai.
output
Output the winner's participant number and the number of fish caught on one line separated by blanks.
Example
Input
6
1 14
2 25
3 42
4 11
5 40
6 37
Output
3 42 | 7 | 0 | #include<iostream>
#include<algorithm>
#include<cstdio>
using namespace std;
int main(){
int n;
int ma,mv;
int a,v;
scanf("%d",&n);
mv=0;
ma=1;
for(int i=0;i<n;i++){
scanf("%d %d",&a,&v);
if(v>mv){
ma=a;
mv=v;
}
else if(v==mv && a<ma){
ma=a;
mv=v;
}
}
printf("%d %d\n",ma,mv);
return 0;
} | CPP |
p00095 Surf Smelt Fishing Contest | A smelt fishing tournament was held at Lake Hibara. The winner is the one who wins the most smelt.
Create a program that reads the list of participant numbers and the number of fish caught and outputs the number of winners and the number of fish caught. If there are multiple winners, output the one with the lowest participant number.
input
The input is given in the following format.
n
a1 v1
a2 v2
::
an vn
n (1 ≤ n ≤ 20) represents the number of participants and ai represents the participant number. Participant numbers are different integers between 1 and n. vi (0 ≤ vi ≤ 100) is the number of animals acquired by the participant ai.
output
Output the winner's participant number and the number of fish caught on one line separated by blanks.
Example
Input
6
1 14
2 25
3 42
4 11
5 40
6 37
Output
3 42 | 7 | 0 | #include<bits/stdc++.h>
using namespace std;
int main(){
pair<int,int> p[100];
int n;
cin>>n;
for(int i=0;i<n;i++)cin>>p[i].second>>p[i].first,p[i].first*=-1;
sort(p,p+n);
cout<<p[0].second<<" "<<-p[0].first<<endl;
return 0;
} | CPP |
p00095 Surf Smelt Fishing Contest | A smelt fishing tournament was held at Lake Hibara. The winner is the one who wins the most smelt.
Create a program that reads the list of participant numbers and the number of fish caught and outputs the number of winners and the number of fish caught. If there are multiple winners, output the one with the lowest participant number.
input
The input is given in the following format.
n
a1 v1
a2 v2
::
an vn
n (1 ≤ n ≤ 20) represents the number of participants and ai represents the participant number. Participant numbers are different integers between 1 and n. vi (0 ≤ vi ≤ 100) is the number of animals acquired by the participant ai.
output
Output the winner's participant number and the number of fish caught on one line separated by blanks.
Example
Input
6
1 14
2 25
3 42
4 11
5 40
6 37
Output
3 42 | 7 | 0 | #include<bits/stdc++.h>
using namespace std;
#define all(vec) vec.begin(),vec.end()
typedef long long int ll;
typedef pair<int,int> P;
const ll MOD=1000000007;
const ll INF=1000000010;
const ll LINF=4000000000000000010LL;
const int MAX=310;
const double EPS=1e-9;
int dx[4]={0,1,0,-1};
int dy[4]={1,0,-1,0};
int main(){
int n;cin>>n;
int ma=-1;int aa=INF;
for(int i=0;i<n;i++){
int a,v;cin>>a>>v;
if(v>ma){
aa=a;
ma=v;
}else if(v==ma){
aa=min(aa,a);
}
}
cout<<aa<<" "<<ma<<endl;
}
| CPP |
p00095 Surf Smelt Fishing Contest | A smelt fishing tournament was held at Lake Hibara. The winner is the one who wins the most smelt.
Create a program that reads the list of participant numbers and the number of fish caught and outputs the number of winners and the number of fish caught. If there are multiple winners, output the one with the lowest participant number.
input
The input is given in the following format.
n
a1 v1
a2 v2
::
an vn
n (1 ≤ n ≤ 20) represents the number of participants and ai represents the participant number. Participant numbers are different integers between 1 and n. vi (0 ≤ vi ≤ 100) is the number of animals acquired by the participant ai.
output
Output the winner's participant number and the number of fish caught on one line separated by blanks.
Example
Input
6
1 14
2 25
3 42
4 11
5 40
6 37
Output
3 42 | 7 | 0 | a={}
for i in range(int(input())):
b,c=map(int,input().split())
a[b]=c
print(*max(a.items(),key=lambda x:x[1])) | PYTHON3 |
p00227 Thanksgiving | As bad weather continues and vegetable prices soar, Seven-Eleven is offering customers bulk purchase sales of vegetables. The store is very busy, as you can get vegetables that are hard to find in stores at reasonable prices.
One day, a group of three good friends living in the Matsunaga housing complex bloomed with an advertisement for Seven-Eleven. Since this sale was called "Customer Thanksgiving Day", the highlight is that the cheapest vegetables in the bag are free. When I read the advertisement, it looks like the following sale.
* Up to m vegetables can be packed in one bag.
* For bags packed with m vegetables, the cheapest vegetables are free.
* Bags with less than m vegetables are not eligible for the discount.
The three went shopping at Seven Mart immediately.
When the three people who met outside the store after shopping were satisfied with the fact that they were able to buy a lot at a low price, they apparently found that they were all buying the same vegetables. One person said, "It's really cheap, isn't it? This is XXX yen!", And the other was surprised, "What? I was ** yen higher than that! Why?", And the rest One of them saw the receipt and noticed that he bought the cheapest one.
Now, how can you pack the bag at the lowest purchase price? Enter the number of vegetables to purchase, the number of vegetables in the bag, and the price of each vegetable, and create a program that outputs the minimum purchase price.
Input
A sequence of multiple datasets is given as input. The end of the input is indicated by two lines of zeros. Each dataset is given in the following format:
n m
p1 p2 ... pn
The first line gives the number of vegetables to buy n (1 ≤ n ≤ 1000) and the number of vegetables to put in the bag m (1 ≤ m ≤ 1000). The second line gives the price pi (10 ≤ pi ≤ 10000) for each vegetable.
The number of datasets does not exceed 100.
Output
Prints the minimum purchase price on one line for each input dataset.
Example
Input
4 2
50 40 100 80
7 3
400 300 100 700 200 600 500
0 0
Output
150
2100 | 7 | 0 | #include<iostream>
#include<algorithm>
#include<functional>
using namespace std;
int main(){
int n,m;
while(cin>>n>>m,n!=0||m!=0){
int a[1000]={0},ans=0;
for(int i=0;i<n;i++)cin>>a[i];
sort(a,a+n,greater<int>());
if(n>=m){
for(int i=0;i<n;i++){
if((i+1)%m==0){
a[i]=0;
}
}
}
for(int i=0;i<n;i++)ans+=a[i];
cout<<ans<<endl;
}
return 0;
} | CPP |
p00227 Thanksgiving | As bad weather continues and vegetable prices soar, Seven-Eleven is offering customers bulk purchase sales of vegetables. The store is very busy, as you can get vegetables that are hard to find in stores at reasonable prices.
One day, a group of three good friends living in the Matsunaga housing complex bloomed with an advertisement for Seven-Eleven. Since this sale was called "Customer Thanksgiving Day", the highlight is that the cheapest vegetables in the bag are free. When I read the advertisement, it looks like the following sale.
* Up to m vegetables can be packed in one bag.
* For bags packed with m vegetables, the cheapest vegetables are free.
* Bags with less than m vegetables are not eligible for the discount.
The three went shopping at Seven Mart immediately.
When the three people who met outside the store after shopping were satisfied with the fact that they were able to buy a lot at a low price, they apparently found that they were all buying the same vegetables. One person said, "It's really cheap, isn't it? This is XXX yen!", And the other was surprised, "What? I was ** yen higher than that! Why?", And the rest One of them saw the receipt and noticed that he bought the cheapest one.
Now, how can you pack the bag at the lowest purchase price? Enter the number of vegetables to purchase, the number of vegetables in the bag, and the price of each vegetable, and create a program that outputs the minimum purchase price.
Input
A sequence of multiple datasets is given as input. The end of the input is indicated by two lines of zeros. Each dataset is given in the following format:
n m
p1 p2 ... pn
The first line gives the number of vegetables to buy n (1 ≤ n ≤ 1000) and the number of vegetables to put in the bag m (1 ≤ m ≤ 1000). The second line gives the price pi (10 ≤ pi ≤ 10000) for each vegetable.
The number of datasets does not exceed 100.
Output
Prints the minimum purchase price on one line for each input dataset.
Example
Input
4 2
50 40 100 80
7 3
400 300 100 700 200 600 500
0 0
Output
150
2100 | 7 | 0 | #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()-m;i>=0;i-=m){
ans -= v[i];
}
cout << ans << endl;
}
} | CPP |
p00227 Thanksgiving | As bad weather continues and vegetable prices soar, Seven-Eleven is offering customers bulk purchase sales of vegetables. The store is very busy, as you can get vegetables that are hard to find in stores at reasonable prices.
One day, a group of three good friends living in the Matsunaga housing complex bloomed with an advertisement for Seven-Eleven. Since this sale was called "Customer Thanksgiving Day", the highlight is that the cheapest vegetables in the bag are free. When I read the advertisement, it looks like the following sale.
* Up to m vegetables can be packed in one bag.
* For bags packed with m vegetables, the cheapest vegetables are free.
* Bags with less than m vegetables are not eligible for the discount.
The three went shopping at Seven Mart immediately.
When the three people who met outside the store after shopping were satisfied with the fact that they were able to buy a lot at a low price, they apparently found that they were all buying the same vegetables. One person said, "It's really cheap, isn't it? This is XXX yen!", And the other was surprised, "What? I was ** yen higher than that! Why?", And the rest One of them saw the receipt and noticed that he bought the cheapest one.
Now, how can you pack the bag at the lowest purchase price? Enter the number of vegetables to purchase, the number of vegetables in the bag, and the price of each vegetable, and create a program that outputs the minimum purchase price.
Input
A sequence of multiple datasets is given as input. The end of the input is indicated by two lines of zeros. Each dataset is given in the following format:
n m
p1 p2 ... pn
The first line gives the number of vegetables to buy n (1 ≤ n ≤ 1000) and the number of vegetables to put in the bag m (1 ≤ m ≤ 1000). The second line gives the price pi (10 ≤ pi ≤ 10000) for each vegetable.
The number of datasets does not exceed 100.
Output
Prints the minimum purchase price on one line for each input dataset.
Example
Input
4 2
50 40 100 80
7 3
400 300 100 700 200 600 500
0 0
Output
150
2100 | 7 | 0 | while True:
try:
n, m = (int(x.strip()) for x in raw_input().split())
if n == 0 and m == 0: break
p = [int(x.strip()) for x in raw_input().split()]
s = sum(p)
p.sort(reverse=True)
for x in p[m - 1::m]:
s -= x
print s
except:
pass | PYTHON |
p00227 Thanksgiving | As bad weather continues and vegetable prices soar, Seven-Eleven is offering customers bulk purchase sales of vegetables. The store is very busy, as you can get vegetables that are hard to find in stores at reasonable prices.
One day, a group of three good friends living in the Matsunaga housing complex bloomed with an advertisement for Seven-Eleven. Since this sale was called "Customer Thanksgiving Day", the highlight is that the cheapest vegetables in the bag are free. When I read the advertisement, it looks like the following sale.
* Up to m vegetables can be packed in one bag.
* For bags packed with m vegetables, the cheapest vegetables are free.
* Bags with less than m vegetables are not eligible for the discount.
The three went shopping at Seven Mart immediately.
When the three people who met outside the store after shopping were satisfied with the fact that they were able to buy a lot at a low price, they apparently found that they were all buying the same vegetables. One person said, "It's really cheap, isn't it? This is XXX yen!", And the other was surprised, "What? I was ** yen higher than that! Why?", And the rest One of them saw the receipt and noticed that he bought the cheapest one.
Now, how can you pack the bag at the lowest purchase price? Enter the number of vegetables to purchase, the number of vegetables in the bag, and the price of each vegetable, and create a program that outputs the minimum purchase price.
Input
A sequence of multiple datasets is given as input. The end of the input is indicated by two lines of zeros. Each dataset is given in the following format:
n m
p1 p2 ... pn
The first line gives the number of vegetables to buy n (1 ≤ n ≤ 1000) and the number of vegetables to put in the bag m (1 ≤ m ≤ 1000). The second line gives the price pi (10 ≤ pi ≤ 10000) for each vegetable.
The number of datasets does not exceed 100.
Output
Prints the minimum purchase price on one line for each input dataset.
Example
Input
4 2
50 40 100 80
7 3
400 300 100 700 200 600 500
0 0
Output
150
2100 | 7 | 0 | #include <iostream>
#include <vector>
#include <algorithm>
using namespace std;
int main(){
int n,m;
while(cin>>n>>m&&!(n==0&&m==0)){
int num=n/m;
vector<int> v;
for(int i = 0; i < n; i++){
int t;
cin>>t;
v.push_back(t);
}
sort(v.begin(),v.end(),greater<int>());
int sum=0;
for(int i = 0; i < n; i++){
if((i+1)%m==0){
}
else
sum+=v[i];
}
cout<<sum<<endl;
}
return 0;
} | CPP |
p00227 Thanksgiving | As bad weather continues and vegetable prices soar, Seven-Eleven is offering customers bulk purchase sales of vegetables. The store is very busy, as you can get vegetables that are hard to find in stores at reasonable prices.
One day, a group of three good friends living in the Matsunaga housing complex bloomed with an advertisement for Seven-Eleven. Since this sale was called "Customer Thanksgiving Day", the highlight is that the cheapest vegetables in the bag are free. When I read the advertisement, it looks like the following sale.
* Up to m vegetables can be packed in one bag.
* For bags packed with m vegetables, the cheapest vegetables are free.
* Bags with less than m vegetables are not eligible for the discount.
The three went shopping at Seven Mart immediately.
When the three people who met outside the store after shopping were satisfied with the fact that they were able to buy a lot at a low price, they apparently found that they were all buying the same vegetables. One person said, "It's really cheap, isn't it? This is XXX yen!", And the other was surprised, "What? I was ** yen higher than that! Why?", And the rest One of them saw the receipt and noticed that he bought the cheapest one.
Now, how can you pack the bag at the lowest purchase price? Enter the number of vegetables to purchase, the number of vegetables in the bag, and the price of each vegetable, and create a program that outputs the minimum purchase price.
Input
A sequence of multiple datasets is given as input. The end of the input is indicated by two lines of zeros. Each dataset is given in the following format:
n m
p1 p2 ... pn
The first line gives the number of vegetables to buy n (1 ≤ n ≤ 1000) and the number of vegetables to put in the bag m (1 ≤ m ≤ 1000). The second line gives the price pi (10 ≤ pi ≤ 10000) for each vegetable.
The number of datasets does not exceed 100.
Output
Prints the minimum purchase price on one line for each input dataset.
Example
Input
4 2
50 40 100 80
7 3
400 300 100 700 200 600 500
0 0
Output
150
2100 | 7 | 0 | import java.util.Arrays;
import java.util.Scanner;
public class Main {
static Scanner sc = new Scanner(System.in);
static int m,n;
static int[] p;
public static void main(String[] args) {
while(read()) solve();
}
private static void solve() {
Arrays.sort(p);
p = reverse(p);
int i = 0;
int sum = 0;
while (m >= i + n) {
for (int j = 0; j < n-1; j++) {
sum += p[i + j];
}
i += n;
}
for (int j = i; j < m; j++) {
sum += p[j];
}
System.out.println(sum);
}
private static int[] reverse(int[] in) {
int[] out = new int[in.length];
for (int i = 0; i < in.length; i++) {
out[i] = in[in.length - 1 - i];
}
return out;
}
private static boolean read() {
m = sc.nextInt();
n = sc.nextInt();
if(m==0 && n==0) return false;
p = new int[m];
for(int i=0; i<m; i++) {
p[i] = sc.nextInt();
}
return true;
}
} | JAVA |
p00227 Thanksgiving | As bad weather continues and vegetable prices soar, Seven-Eleven is offering customers bulk purchase sales of vegetables. The store is very busy, as you can get vegetables that are hard to find in stores at reasonable prices.
One day, a group of three good friends living in the Matsunaga housing complex bloomed with an advertisement for Seven-Eleven. Since this sale was called "Customer Thanksgiving Day", the highlight is that the cheapest vegetables in the bag are free. When I read the advertisement, it looks like the following sale.
* Up to m vegetables can be packed in one bag.
* For bags packed with m vegetables, the cheapest vegetables are free.
* Bags with less than m vegetables are not eligible for the discount.
The three went shopping at Seven Mart immediately.
When the three people who met outside the store after shopping were satisfied with the fact that they were able to buy a lot at a low price, they apparently found that they were all buying the same vegetables. One person said, "It's really cheap, isn't it? This is XXX yen!", And the other was surprised, "What? I was ** yen higher than that! Why?", And the rest One of them saw the receipt and noticed that he bought the cheapest one.
Now, how can you pack the bag at the lowest purchase price? Enter the number of vegetables to purchase, the number of vegetables in the bag, and the price of each vegetable, and create a program that outputs the minimum purchase price.
Input
A sequence of multiple datasets is given as input. The end of the input is indicated by two lines of zeros. Each dataset is given in the following format:
n m
p1 p2 ... pn
The first line gives the number of vegetables to buy n (1 ≤ n ≤ 1000) and the number of vegetables to put in the bag m (1 ≤ m ≤ 1000). The second line gives the price pi (10 ≤ pi ≤ 10000) for each vegetable.
The number of datasets does not exceed 100.
Output
Prints the minimum purchase price on one line for each input dataset.
Example
Input
4 2
50 40 100 80
7 3
400 300 100 700 200 600 500
0 0
Output
150
2100 | 7 | 0 | #include<iostream>
#include<algorithm>
#include<functional>
#define MAX 1000
int main(){
int n,m,p[MAX];
while(1){
int f=0,m1=0;
std::cin>>n>>m;
if(n==0&&m==0)
break;
for(int i=0;i<n;++i){
std::cin>>p[i];
m1+=p[i];
}
std::sort(p,p+n,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<<m1-f<<std::endl;
}
return 0;
} | CPP |
p00227 Thanksgiving | As bad weather continues and vegetable prices soar, Seven-Eleven is offering customers bulk purchase sales of vegetables. The store is very busy, as you can get vegetables that are hard to find in stores at reasonable prices.
One day, a group of three good friends living in the Matsunaga housing complex bloomed with an advertisement for Seven-Eleven. Since this sale was called "Customer Thanksgiving Day", the highlight is that the cheapest vegetables in the bag are free. When I read the advertisement, it looks like the following sale.
* Up to m vegetables can be packed in one bag.
* For bags packed with m vegetables, the cheapest vegetables are free.
* Bags with less than m vegetables are not eligible for the discount.
The three went shopping at Seven Mart immediately.
When the three people who met outside the store after shopping were satisfied with the fact that they were able to buy a lot at a low price, they apparently found that they were all buying the same vegetables. One person said, "It's really cheap, isn't it? This is XXX yen!", And the other was surprised, "What? I was ** yen higher than that! Why?", And the rest One of them saw the receipt and noticed that he bought the cheapest one.
Now, how can you pack the bag at the lowest purchase price? Enter the number of vegetables to purchase, the number of vegetables in the bag, and the price of each vegetable, and create a program that outputs the minimum purchase price.
Input
A sequence of multiple datasets is given as input. The end of the input is indicated by two lines of zeros. Each dataset is given in the following format:
n m
p1 p2 ... pn
The first line gives the number of vegetables to buy n (1 ≤ n ≤ 1000) and the number of vegetables to put in the bag m (1 ≤ m ≤ 1000). The second line gives the price pi (10 ≤ pi ≤ 10000) for each vegetable.
The number of datasets does not exceed 100.
Output
Prints the minimum purchase price on one line for each input dataset.
Example
Input
4 2
50 40 100 80
7 3
400 300 100 700 200 600 500
0 0
Output
150
2100 | 7 | 0 | #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;
}
} | CPP |
p00227 Thanksgiving | As bad weather continues and vegetable prices soar, Seven-Eleven is offering customers bulk purchase sales of vegetables. The store is very busy, as you can get vegetables that are hard to find in stores at reasonable prices.
One day, a group of three good friends living in the Matsunaga housing complex bloomed with an advertisement for Seven-Eleven. Since this sale was called "Customer Thanksgiving Day", the highlight is that the cheapest vegetables in the bag are free. When I read the advertisement, it looks like the following sale.
* Up to m vegetables can be packed in one bag.
* For bags packed with m vegetables, the cheapest vegetables are free.
* Bags with less than m vegetables are not eligible for the discount.
The three went shopping at Seven Mart immediately.
When the three people who met outside the store after shopping were satisfied with the fact that they were able to buy a lot at a low price, they apparently found that they were all buying the same vegetables. One person said, "It's really cheap, isn't it? This is XXX yen!", And the other was surprised, "What? I was ** yen higher than that! Why?", And the rest One of them saw the receipt and noticed that he bought the cheapest one.
Now, how can you pack the bag at the lowest purchase price? Enter the number of vegetables to purchase, the number of vegetables in the bag, and the price of each vegetable, and create a program that outputs the minimum purchase price.
Input
A sequence of multiple datasets is given as input. The end of the input is indicated by two lines of zeros. Each dataset is given in the following format:
n m
p1 p2 ... pn
The first line gives the number of vegetables to buy n (1 ≤ n ≤ 1000) and the number of vegetables to put in the bag m (1 ≤ m ≤ 1000). The second line gives the price pi (10 ≤ pi ≤ 10000) for each vegetable.
The number of datasets does not exceed 100.
Output
Prints the minimum purchase price on one line for each input dataset.
Example
Input
4 2
50 40 100 80
7 3
400 300 100 700 200 600 500
0 0
Output
150
2100 | 7 | 0 | #include<bits/stdc++.h>
using namespace std;
int main(){
while(1){
long long n,m;
long long sum=0;
cin>>n>>m;
if(n==0&&m==0) break;
long long p[1005];
for(int i=0;i<n;i++){
cin>>p[i];
sum+=p[i];
}
sort(p,p+n,greater<long long>());
for(int i=1;i<=n;i++){
if(i%m==0){
sum-=p[i-1];
}
}
cout<<sum<<endl;
}
} | CPP |
p00227 Thanksgiving | As bad weather continues and vegetable prices soar, Seven-Eleven is offering customers bulk purchase sales of vegetables. The store is very busy, as you can get vegetables that are hard to find in stores at reasonable prices.
One day, a group of three good friends living in the Matsunaga housing complex bloomed with an advertisement for Seven-Eleven. Since this sale was called "Customer Thanksgiving Day", the highlight is that the cheapest vegetables in the bag are free. When I read the advertisement, it looks like the following sale.
* Up to m vegetables can be packed in one bag.
* For bags packed with m vegetables, the cheapest vegetables are free.
* Bags with less than m vegetables are not eligible for the discount.
The three went shopping at Seven Mart immediately.
When the three people who met outside the store after shopping were satisfied with the fact that they were able to buy a lot at a low price, they apparently found that they were all buying the same vegetables. One person said, "It's really cheap, isn't it? This is XXX yen!", And the other was surprised, "What? I was ** yen higher than that! Why?", And the rest One of them saw the receipt and noticed that he bought the cheapest one.
Now, how can you pack the bag at the lowest purchase price? Enter the number of vegetables to purchase, the number of vegetables in the bag, and the price of each vegetable, and create a program that outputs the minimum purchase price.
Input
A sequence of multiple datasets is given as input. The end of the input is indicated by two lines of zeros. Each dataset is given in the following format:
n m
p1 p2 ... pn
The first line gives the number of vegetables to buy n (1 ≤ n ≤ 1000) and the number of vegetables to put in the bag m (1 ≤ m ≤ 1000). The second line gives the price pi (10 ≤ pi ≤ 10000) for each vegetable.
The number of datasets does not exceed 100.
Output
Prints the minimum purchase price on one line for each input dataset.
Example
Input
4 2
50 40 100 80
7 3
400 300 100 700 200 600 500
0 0
Output
150
2100 | 7 | 0 | import java.util.*;
import java.lang.*;
import java.math.*;
public class Main {
Scanner sc = new Scanner(System.in);
void run() {
for (;;) {
int n = sc.nextInt();
int m = sc.nextInt();
if ((n | m) == 0) {
break;
}
int y[] = new int[n];
for (int i = 0; i < n; i++) {
y[i] = sc.nextInt();
}
Arrays.sort(y);
int ans = 0;
for (int i = 0; i < n; i++) {
if ((i + 1) % m != 0) {
ans += y[y.length - 1 - i];
}
}
System.out.println(ans);
}
}
public static void main(String[] args) {
Main m = new Main();
m.run();
}
} | JAVA |
p00227 Thanksgiving | As bad weather continues and vegetable prices soar, Seven-Eleven is offering customers bulk purchase sales of vegetables. The store is very busy, as you can get vegetables that are hard to find in stores at reasonable prices.
One day, a group of three good friends living in the Matsunaga housing complex bloomed with an advertisement for Seven-Eleven. Since this sale was called "Customer Thanksgiving Day", the highlight is that the cheapest vegetables in the bag are free. When I read the advertisement, it looks like the following sale.
* Up to m vegetables can be packed in one bag.
* For bags packed with m vegetables, the cheapest vegetables are free.
* Bags with less than m vegetables are not eligible for the discount.
The three went shopping at Seven Mart immediately.
When the three people who met outside the store after shopping were satisfied with the fact that they were able to buy a lot at a low price, they apparently found that they were all buying the same vegetables. One person said, "It's really cheap, isn't it? This is XXX yen!", And the other was surprised, "What? I was ** yen higher than that! Why?", And the rest One of them saw the receipt and noticed that he bought the cheapest one.
Now, how can you pack the bag at the lowest purchase price? Enter the number of vegetables to purchase, the number of vegetables in the bag, and the price of each vegetable, and create a program that outputs the minimum purchase price.
Input
A sequence of multiple datasets is given as input. The end of the input is indicated by two lines of zeros. Each dataset is given in the following format:
n m
p1 p2 ... pn
The first line gives the number of vegetables to buy n (1 ≤ n ≤ 1000) and the number of vegetables to put in the bag m (1 ≤ m ≤ 1000). The second line gives the price pi (10 ≤ pi ≤ 10000) for each vegetable.
The number of datasets does not exceed 100.
Output
Prints the minimum purchase price on one line for each input dataset.
Example
Input
4 2
50 40 100 80
7 3
400 300 100 700 200 600 500
0 0
Output
150
2100 | 7 | 0 | # -*- coding: utf-8 -*-
"""
Thanksgiving
http://judge.u-aizu.ac.jp/onlinejudge/description.jsp?id=0227
"""
import sys
def solve(n, m, prices):
ans = 0
for i in range(0, n, m):
t = prices[i:i+m]
if len(t) == m:
t[-1] = 0
ans += sum(t)
return ans
def main(args):
while True:
n, m = map(int, input().split())
if n == 0 and m == 0:
break
prices = sorted([int(p) for p in input().split()], reverse=True)
ans = solve(n, m, prices)
print(ans)
if __name__ == '__main__':
main(sys.argv[1:])
| PYTHON3 |
p00227 Thanksgiving | As bad weather continues and vegetable prices soar, Seven-Eleven is offering customers bulk purchase sales of vegetables. The store is very busy, as you can get vegetables that are hard to find in stores at reasonable prices.
One day, a group of three good friends living in the Matsunaga housing complex bloomed with an advertisement for Seven-Eleven. Since this sale was called "Customer Thanksgiving Day", the highlight is that the cheapest vegetables in the bag are free. When I read the advertisement, it looks like the following sale.
* Up to m vegetables can be packed in one bag.
* For bags packed with m vegetables, the cheapest vegetables are free.
* Bags with less than m vegetables are not eligible for the discount.
The three went shopping at Seven Mart immediately.
When the three people who met outside the store after shopping were satisfied with the fact that they were able to buy a lot at a low price, they apparently found that they were all buying the same vegetables. One person said, "It's really cheap, isn't it? This is XXX yen!", And the other was surprised, "What? I was ** yen higher than that! Why?", And the rest One of them saw the receipt and noticed that he bought the cheapest one.
Now, how can you pack the bag at the lowest purchase price? Enter the number of vegetables to purchase, the number of vegetables in the bag, and the price of each vegetable, and create a program that outputs the minimum purchase price.
Input
A sequence of multiple datasets is given as input. The end of the input is indicated by two lines of zeros. Each dataset is given in the following format:
n m
p1 p2 ... pn
The first line gives the number of vegetables to buy n (1 ≤ n ≤ 1000) and the number of vegetables to put in the bag m (1 ≤ m ≤ 1000). The second line gives the price pi (10 ≤ pi ≤ 10000) for each vegetable.
The number of datasets does not exceed 100.
Output
Prints the minimum purchase price on one line for each input dataset.
Example
Input
4 2
50 40 100 80
7 3
400 300 100 700 200 600 500
0 0
Output
150
2100 | 7 | 0 | import java.util.*;
public class Main {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
while(true){
int n = sc.nextInt();
int m = sc.nextInt();
if(n==0 && m==0)break;
int[] p = new int[n];
for(int i=0;i<n;i++){
p[i] = sc.nextInt();
}
Arrays.sort(p);
int sum = 0;
int count = 0;
for(int i=n-1;i>=0;i--){
if(count==m-1){
count=0;
}else{
sum += p[i];
count++;
}
}
System.out.println(sum);
}
}
} | JAVA |
p00227 Thanksgiving | As bad weather continues and vegetable prices soar, Seven-Eleven is offering customers bulk purchase sales of vegetables. The store is very busy, as you can get vegetables that are hard to find in stores at reasonable prices.
One day, a group of three good friends living in the Matsunaga housing complex bloomed with an advertisement for Seven-Eleven. Since this sale was called "Customer Thanksgiving Day", the highlight is that the cheapest vegetables in the bag are free. When I read the advertisement, it looks like the following sale.
* Up to m vegetables can be packed in one bag.
* For bags packed with m vegetables, the cheapest vegetables are free.
* Bags with less than m vegetables are not eligible for the discount.
The three went shopping at Seven Mart immediately.
When the three people who met outside the store after shopping were satisfied with the fact that they were able to buy a lot at a low price, they apparently found that they were all buying the same vegetables. One person said, "It's really cheap, isn't it? This is XXX yen!", And the other was surprised, "What? I was ** yen higher than that! Why?", And the rest One of them saw the receipt and noticed that he bought the cheapest one.
Now, how can you pack the bag at the lowest purchase price? Enter the number of vegetables to purchase, the number of vegetables in the bag, and the price of each vegetable, and create a program that outputs the minimum purchase price.
Input
A sequence of multiple datasets is given as input. The end of the input is indicated by two lines of zeros. Each dataset is given in the following format:
n m
p1 p2 ... pn
The first line gives the number of vegetables to buy n (1 ≤ n ≤ 1000) and the number of vegetables to put in the bag m (1 ≤ m ≤ 1000). The second line gives the price pi (10 ≤ pi ≤ 10000) for each vegetable.
The number of datasets does not exceed 100.
Output
Prints the minimum purchase price on one line for each input dataset.
Example
Input
4 2
50 40 100 80
7 3
400 300 100 700 200 600 500
0 0
Output
150
2100 | 7 | 0 | #include<cstdio>
#include<algorithm>
#include<functional>
#define rep(i,n) for(int i=0;i<n;i++)
using namespace std;
int main(){
for(int n,m;scanf("%d%d",&n,&m),n;){
int p[1000];
rep(i,n) scanf("%d",p+i);
sort(p,p+n,greater<int>());
int total=0;
rep(i,n) if((i+1)%m!=0) total+=p[i];
printf("%d\n",total);
}
return 0;
} | CPP |
p00227 Thanksgiving | As bad weather continues and vegetable prices soar, Seven-Eleven is offering customers bulk purchase sales of vegetables. The store is very busy, as you can get vegetables that are hard to find in stores at reasonable prices.
One day, a group of three good friends living in the Matsunaga housing complex bloomed with an advertisement for Seven-Eleven. Since this sale was called "Customer Thanksgiving Day", the highlight is that the cheapest vegetables in the bag are free. When I read the advertisement, it looks like the following sale.
* Up to m vegetables can be packed in one bag.
* For bags packed with m vegetables, the cheapest vegetables are free.
* Bags with less than m vegetables are not eligible for the discount.
The three went shopping at Seven Mart immediately.
When the three people who met outside the store after shopping were satisfied with the fact that they were able to buy a lot at a low price, they apparently found that they were all buying the same vegetables. One person said, "It's really cheap, isn't it? This is XXX yen!", And the other was surprised, "What? I was ** yen higher than that! Why?", And the rest One of them saw the receipt and noticed that he bought the cheapest one.
Now, how can you pack the bag at the lowest purchase price? Enter the number of vegetables to purchase, the number of vegetables in the bag, and the price of each vegetable, and create a program that outputs the minimum purchase price.
Input
A sequence of multiple datasets is given as input. The end of the input is indicated by two lines of zeros. Each dataset is given in the following format:
n m
p1 p2 ... pn
The first line gives the number of vegetables to buy n (1 ≤ n ≤ 1000) and the number of vegetables to put in the bag m (1 ≤ m ≤ 1000). The second line gives the price pi (10 ≤ pi ≤ 10000) for each vegetable.
The number of datasets does not exceed 100.
Output
Prints the minimum purchase price on one line for each input dataset.
Example
Input
4 2
50 40 100 80
7 3
400 300 100 700 200 600 500
0 0
Output
150
2100 | 7 | 0 | #include<stdio.h>
int main(){
int N,M;
int n[1001]={};
while(1)
{
int s=0;
scanf("%d %d",&N,&M);
if(N==0&&M==0)break;
for(int i=1;i<=N;i++)
scanf("%d",&n[i]);
for(int i=1;i<=N;i++)
for(int j=N;j>i;j--)
if(n[j]>n[j-1]){int t=n[j-1];n[j-1]=n[j];n[j]=t;}
for(int i=1;i<=N;i++)
{if(i%M!=0)s+=n[i];}
printf("%d\n",s);
}
return 0;
} | CPP |
p00227 Thanksgiving | As bad weather continues and vegetable prices soar, Seven-Eleven is offering customers bulk purchase sales of vegetables. The store is very busy, as you can get vegetables that are hard to find in stores at reasonable prices.
One day, a group of three good friends living in the Matsunaga housing complex bloomed with an advertisement for Seven-Eleven. Since this sale was called "Customer Thanksgiving Day", the highlight is that the cheapest vegetables in the bag are free. When I read the advertisement, it looks like the following sale.
* Up to m vegetables can be packed in one bag.
* For bags packed with m vegetables, the cheapest vegetables are free.
* Bags with less than m vegetables are not eligible for the discount.
The three went shopping at Seven Mart immediately.
When the three people who met outside the store after shopping were satisfied with the fact that they were able to buy a lot at a low price, they apparently found that they were all buying the same vegetables. One person said, "It's really cheap, isn't it? This is XXX yen!", And the other was surprised, "What? I was ** yen higher than that! Why?", And the rest One of them saw the receipt and noticed that he bought the cheapest one.
Now, how can you pack the bag at the lowest purchase price? Enter the number of vegetables to purchase, the number of vegetables in the bag, and the price of each vegetable, and create a program that outputs the minimum purchase price.
Input
A sequence of multiple datasets is given as input. The end of the input is indicated by two lines of zeros. Each dataset is given in the following format:
n m
p1 p2 ... pn
The first line gives the number of vegetables to buy n (1 ≤ n ≤ 1000) and the number of vegetables to put in the bag m (1 ≤ m ≤ 1000). The second line gives the price pi (10 ≤ pi ≤ 10000) for each vegetable.
The number of datasets does not exceed 100.
Output
Prints the minimum purchase price on one line for each input dataset.
Example
Input
4 2
50 40 100 80
7 3
400 300 100 700 200 600 500
0 0
Output
150
2100 | 7 | 0 | #include <iostream>
#include <string>
#include <algorithm>
using namespace std;
int main() {
int cnt,hukuro;
int n,m,yasai[1000],total=0;
while(1){
cin>>n>>m;
if(n==0&&m==0)break;
cnt=0;
hukuro=n/m;
for(int i=0;i<n;i++){
cin>>yasai[i];
}
sort(yasai,yasai+n);
reverse(yasai,yasai+n);
for(int i=0;i<n;i++){
if((i+1)%m!=0)total+=yasai[i];
cnt++;
}
cout<<total<<endl;
total=0;
}
return 0 ;
} | CPP |
p00227 Thanksgiving | As bad weather continues and vegetable prices soar, Seven-Eleven is offering customers bulk purchase sales of vegetables. The store is very busy, as you can get vegetables that are hard to find in stores at reasonable prices.
One day, a group of three good friends living in the Matsunaga housing complex bloomed with an advertisement for Seven-Eleven. Since this sale was called "Customer Thanksgiving Day", the highlight is that the cheapest vegetables in the bag are free. When I read the advertisement, it looks like the following sale.
* Up to m vegetables can be packed in one bag.
* For bags packed with m vegetables, the cheapest vegetables are free.
* Bags with less than m vegetables are not eligible for the discount.
The three went shopping at Seven Mart immediately.
When the three people who met outside the store after shopping were satisfied with the fact that they were able to buy a lot at a low price, they apparently found that they were all buying the same vegetables. One person said, "It's really cheap, isn't it? This is XXX yen!", And the other was surprised, "What? I was ** yen higher than that! Why?", And the rest One of them saw the receipt and noticed that he bought the cheapest one.
Now, how can you pack the bag at the lowest purchase price? Enter the number of vegetables to purchase, the number of vegetables in the bag, and the price of each vegetable, and create a program that outputs the minimum purchase price.
Input
A sequence of multiple datasets is given as input. The end of the input is indicated by two lines of zeros. Each dataset is given in the following format:
n m
p1 p2 ... pn
The first line gives the number of vegetables to buy n (1 ≤ n ≤ 1000) and the number of vegetables to put in the bag m (1 ≤ m ≤ 1000). The second line gives the price pi (10 ≤ pi ≤ 10000) for each vegetable.
The number of datasets does not exceed 100.
Output
Prints the minimum purchase price on one line for each input dataset.
Example
Input
4 2
50 40 100 80
7 3
400 300 100 700 200 600 500
0 0
Output
150
2100 | 7 | 0 | #include<bits/stdc++.h>
using namespace std;
const int INF = 1 << 30;
int main()
{
int n, m, p[1000];
while(cin >> n >> m, n) {
for(int i = 0; i < n; i++) {
cin >> p[i];
}
sort(p, p + n);
int ret = accumulate(p, p + n, 0);
for(int i = n - m; i >= 0; i -= m) {
ret -= p[i];
}
cout << ret << endl;
}
} | CPP |
p00227 Thanksgiving | As bad weather continues and vegetable prices soar, Seven-Eleven is offering customers bulk purchase sales of vegetables. The store is very busy, as you can get vegetables that are hard to find in stores at reasonable prices.
One day, a group of three good friends living in the Matsunaga housing complex bloomed with an advertisement for Seven-Eleven. Since this sale was called "Customer Thanksgiving Day", the highlight is that the cheapest vegetables in the bag are free. When I read the advertisement, it looks like the following sale.
* Up to m vegetables can be packed in one bag.
* For bags packed with m vegetables, the cheapest vegetables are free.
* Bags with less than m vegetables are not eligible for the discount.
The three went shopping at Seven Mart immediately.
When the three people who met outside the store after shopping were satisfied with the fact that they were able to buy a lot at a low price, they apparently found that they were all buying the same vegetables. One person said, "It's really cheap, isn't it? This is XXX yen!", And the other was surprised, "What? I was ** yen higher than that! Why?", And the rest One of them saw the receipt and noticed that he bought the cheapest one.
Now, how can you pack the bag at the lowest purchase price? Enter the number of vegetables to purchase, the number of vegetables in the bag, and the price of each vegetable, and create a program that outputs the minimum purchase price.
Input
A sequence of multiple datasets is given as input. The end of the input is indicated by two lines of zeros. Each dataset is given in the following format:
n m
p1 p2 ... pn
The first line gives the number of vegetables to buy n (1 ≤ n ≤ 1000) and the number of vegetables to put in the bag m (1 ≤ m ≤ 1000). The second line gives the price pi (10 ≤ pi ≤ 10000) for each vegetable.
The number of datasets does not exceed 100.
Output
Prints the minimum purchase price on one line for each input dataset.
Example
Input
4 2
50 40 100 80
7 3
400 300 100 700 200 600 500
0 0
Output
150
2100 | 7 | 0 | #include<cstdio>
#include<algorithm>
using namespace std;
int main(){
int n,m;
while(scanf("%d%d",&n,&m),n,m){
int yasai[1024]={0};
for(int i = 0;i < n; i++){
scanf("%d",&yasai[i]);
}
sort(yasai,yasai+n);
for(int i = n;i >= 0; i-=m){
yasai[i] = 0;
}
int ans=0;
for(int i = 0;i < n; i++){
ans += yasai[i];
}
printf("%d\n",ans);
}
return 0;
} | CPP |
p00227 Thanksgiving | As bad weather continues and vegetable prices soar, Seven-Eleven is offering customers bulk purchase sales of vegetables. The store is very busy, as you can get vegetables that are hard to find in stores at reasonable prices.
One day, a group of three good friends living in the Matsunaga housing complex bloomed with an advertisement for Seven-Eleven. Since this sale was called "Customer Thanksgiving Day", the highlight is that the cheapest vegetables in the bag are free. When I read the advertisement, it looks like the following sale.
* Up to m vegetables can be packed in one bag.
* For bags packed with m vegetables, the cheapest vegetables are free.
* Bags with less than m vegetables are not eligible for the discount.
The three went shopping at Seven Mart immediately.
When the three people who met outside the store after shopping were satisfied with the fact that they were able to buy a lot at a low price, they apparently found that they were all buying the same vegetables. One person said, "It's really cheap, isn't it? This is XXX yen!", And the other was surprised, "What? I was ** yen higher than that! Why?", And the rest One of them saw the receipt and noticed that he bought the cheapest one.
Now, how can you pack the bag at the lowest purchase price? Enter the number of vegetables to purchase, the number of vegetables in the bag, and the price of each vegetable, and create a program that outputs the minimum purchase price.
Input
A sequence of multiple datasets is given as input. The end of the input is indicated by two lines of zeros. Each dataset is given in the following format:
n m
p1 p2 ... pn
The first line gives the number of vegetables to buy n (1 ≤ n ≤ 1000) and the number of vegetables to put in the bag m (1 ≤ m ≤ 1000). The second line gives the price pi (10 ≤ pi ≤ 10000) for each vegetable.
The number of datasets does not exceed 100.
Output
Prints the minimum purchase price on one line for each input dataset.
Example
Input
4 2
50 40 100 80
7 3
400 300 100 700 200 600 500
0 0
Output
150
2100 | 7 | 0 | #include <iostream>
#include <algorithm>
using namespace std;
const int N_MAX = 1000;
int n, m;
int p[N_MAX];
int main () {
while (cin >> n >> m, n || m) {
int 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;
}
return 0;
} | CPP |
p00227 Thanksgiving | As bad weather continues and vegetable prices soar, Seven-Eleven is offering customers bulk purchase sales of vegetables. The store is very busy, as you can get vegetables that are hard to find in stores at reasonable prices.
One day, a group of three good friends living in the Matsunaga housing complex bloomed with an advertisement for Seven-Eleven. Since this sale was called "Customer Thanksgiving Day", the highlight is that the cheapest vegetables in the bag are free. When I read the advertisement, it looks like the following sale.
* Up to m vegetables can be packed in one bag.
* For bags packed with m vegetables, the cheapest vegetables are free.
* Bags with less than m vegetables are not eligible for the discount.
The three went shopping at Seven Mart immediately.
When the three people who met outside the store after shopping were satisfied with the fact that they were able to buy a lot at a low price, they apparently found that they were all buying the same vegetables. One person said, "It's really cheap, isn't it? This is XXX yen!", And the other was surprised, "What? I was ** yen higher than that! Why?", And the rest One of them saw the receipt and noticed that he bought the cheapest one.
Now, how can you pack the bag at the lowest purchase price? Enter the number of vegetables to purchase, the number of vegetables in the bag, and the price of each vegetable, and create a program that outputs the minimum purchase price.
Input
A sequence of multiple datasets is given as input. The end of the input is indicated by two lines of zeros. Each dataset is given in the following format:
n m
p1 p2 ... pn
The first line gives the number of vegetables to buy n (1 ≤ n ≤ 1000) and the number of vegetables to put in the bag m (1 ≤ m ≤ 1000). The second line gives the price pi (10 ≤ pi ≤ 10000) for each vegetable.
The number of datasets does not exceed 100.
Output
Prints the minimum purchase price on one line for each input dataset.
Example
Input
4 2
50 40 100 80
7 3
400 300 100 700 200 600 500
0 0
Output
150
2100 | 7 | 0 | import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
import java.util.LinkedList;
import java.util.Scanner;
public class Main {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
while(true){
final int n = sc.nextInt();
final int m = sc.nextInt();
if(n == 0 && m == 0){
break;
}
LinkedList<Integer> list = new LinkedList<Integer>();
for(int i = 0; i < n; i++){
list.add(sc.nextInt());
}
Collections.sort(list);
Collections.reverse(list);
int cost = 0;
while(list.size() >= m){
for(int i = 0; i < (m - 1); i++){
cost += list.poll();
}
list.poll();
}
if(!list.isEmpty()){
for(int i : list){
cost += i;
}
}
System.out.println(cost);
}
}
} | JAVA |
p00227 Thanksgiving | As bad weather continues and vegetable prices soar, Seven-Eleven is offering customers bulk purchase sales of vegetables. The store is very busy, as you can get vegetables that are hard to find in stores at reasonable prices.
One day, a group of three good friends living in the Matsunaga housing complex bloomed with an advertisement for Seven-Eleven. Since this sale was called "Customer Thanksgiving Day", the highlight is that the cheapest vegetables in the bag are free. When I read the advertisement, it looks like the following sale.
* Up to m vegetables can be packed in one bag.
* For bags packed with m vegetables, the cheapest vegetables are free.
* Bags with less than m vegetables are not eligible for the discount.
The three went shopping at Seven Mart immediately.
When the three people who met outside the store after shopping were satisfied with the fact that they were able to buy a lot at a low price, they apparently found that they were all buying the same vegetables. One person said, "It's really cheap, isn't it? This is XXX yen!", And the other was surprised, "What? I was ** yen higher than that! Why?", And the rest One of them saw the receipt and noticed that he bought the cheapest one.
Now, how can you pack the bag at the lowest purchase price? Enter the number of vegetables to purchase, the number of vegetables in the bag, and the price of each vegetable, and create a program that outputs the minimum purchase price.
Input
A sequence of multiple datasets is given as input. The end of the input is indicated by two lines of zeros. Each dataset is given in the following format:
n m
p1 p2 ... pn
The first line gives the number of vegetables to buy n (1 ≤ n ≤ 1000) and the number of vegetables to put in the bag m (1 ≤ m ≤ 1000). The second line gives the price pi (10 ≤ pi ≤ 10000) for each vegetable.
The number of datasets does not exceed 100.
Output
Prints the minimum purchase price on one line for each input dataset.
Example
Input
4 2
50 40 100 80
7 3
400 300 100 700 200 600 500
0 0
Output
150
2100 | 7 | 0 | #include <bits/stdc++.h>
using namespace std;
int main(){
int n,m;
while(cin>>n>>m&&n!=0&&m!=0){
int sum=0;
vector<int>data;
for(int i=0;i<n;i++){
int p;
cin>>p;
sum+=p;
data.push_back(p);
}
sort(data.begin(),data.end(),greater<int>());
for(int i=m-1;i<n;i+=m){
sum-=data[i];
}
cout<<sum<<endl;
}
} | CPP |
p00227 Thanksgiving | As bad weather continues and vegetable prices soar, Seven-Eleven is offering customers bulk purchase sales of vegetables. The store is very busy, as you can get vegetables that are hard to find in stores at reasonable prices.
One day, a group of three good friends living in the Matsunaga housing complex bloomed with an advertisement for Seven-Eleven. Since this sale was called "Customer Thanksgiving Day", the highlight is that the cheapest vegetables in the bag are free. When I read the advertisement, it looks like the following sale.
* Up to m vegetables can be packed in one bag.
* For bags packed with m vegetables, the cheapest vegetables are free.
* Bags with less than m vegetables are not eligible for the discount.
The three went shopping at Seven Mart immediately.
When the three people who met outside the store after shopping were satisfied with the fact that they were able to buy a lot at a low price, they apparently found that they were all buying the same vegetables. One person said, "It's really cheap, isn't it? This is XXX yen!", And the other was surprised, "What? I was ** yen higher than that! Why?", And the rest One of them saw the receipt and noticed that he bought the cheapest one.
Now, how can you pack the bag at the lowest purchase price? Enter the number of vegetables to purchase, the number of vegetables in the bag, and the price of each vegetable, and create a program that outputs the minimum purchase price.
Input
A sequence of multiple datasets is given as input. The end of the input is indicated by two lines of zeros. Each dataset is given in the following format:
n m
p1 p2 ... pn
The first line gives the number of vegetables to buy n (1 ≤ n ≤ 1000) and the number of vegetables to put in the bag m (1 ≤ m ≤ 1000). The second line gives the price pi (10 ≤ pi ≤ 10000) for each vegetable.
The number of datasets does not exceed 100.
Output
Prints the minimum purchase price on one line for each input dataset.
Example
Input
4 2
50 40 100 80
7 3
400 300 100 700 200 600 500
0 0
Output
150
2100 | 7 | 0 | import java.util.*;class Main{public static void main(String[]z){Scanner s=new Scanner(System.in);for(int n,m,r,i;(n=s.nextInt())>0;System.out.println(r)){m=s.nextInt();int[]a=new int[n];for(i=r=0;i<n;)r+=a[i++]=s.nextInt();Arrays.sort(a);for(i=n-m;i>=0;i-=m)r-=a[i];}}} | JAVA |
p00227 Thanksgiving | As bad weather continues and vegetable prices soar, Seven-Eleven is offering customers bulk purchase sales of vegetables. The store is very busy, as you can get vegetables that are hard to find in stores at reasonable prices.
One day, a group of three good friends living in the Matsunaga housing complex bloomed with an advertisement for Seven-Eleven. Since this sale was called "Customer Thanksgiving Day", the highlight is that the cheapest vegetables in the bag are free. When I read the advertisement, it looks like the following sale.
* Up to m vegetables can be packed in one bag.
* For bags packed with m vegetables, the cheapest vegetables are free.
* Bags with less than m vegetables are not eligible for the discount.
The three went shopping at Seven Mart immediately.
When the three people who met outside the store after shopping were satisfied with the fact that they were able to buy a lot at a low price, they apparently found that they were all buying the same vegetables. One person said, "It's really cheap, isn't it? This is XXX yen!", And the other was surprised, "What? I was ** yen higher than that! Why?", And the rest One of them saw the receipt and noticed that he bought the cheapest one.
Now, how can you pack the bag at the lowest purchase price? Enter the number of vegetables to purchase, the number of vegetables in the bag, and the price of each vegetable, and create a program that outputs the minimum purchase price.
Input
A sequence of multiple datasets is given as input. The end of the input is indicated by two lines of zeros. Each dataset is given in the following format:
n m
p1 p2 ... pn
The first line gives the number of vegetables to buy n (1 ≤ n ≤ 1000) and the number of vegetables to put in the bag m (1 ≤ m ≤ 1000). The second line gives the price pi (10 ≤ pi ≤ 10000) for each vegetable.
The number of datasets does not exceed 100.
Output
Prints the minimum purchase price on one line for each input dataset.
Example
Input
4 2
50 40 100 80
7 3
400 300 100 700 200 600 500
0 0
Output
150
2100 | 7 | 0 | #include <iostream>
#include <cstdio>
#include <algorithm>
#include <vector>
#include <sstream>
#include <cmath>
#include <queue>
using namespace std;
int main(){
int n, m;
while(true){
cin >> n >> m;
if(n == 0 && m == 0){
break;
}
int p[200000];
long long int sum = 0;
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;
} | CPP |
p00227 Thanksgiving | As bad weather continues and vegetable prices soar, Seven-Eleven is offering customers bulk purchase sales of vegetables. The store is very busy, as you can get vegetables that are hard to find in stores at reasonable prices.
One day, a group of three good friends living in the Matsunaga housing complex bloomed with an advertisement for Seven-Eleven. Since this sale was called "Customer Thanksgiving Day", the highlight is that the cheapest vegetables in the bag are free. When I read the advertisement, it looks like the following sale.
* Up to m vegetables can be packed in one bag.
* For bags packed with m vegetables, the cheapest vegetables are free.
* Bags with less than m vegetables are not eligible for the discount.
The three went shopping at Seven Mart immediately.
When the three people who met outside the store after shopping were satisfied with the fact that they were able to buy a lot at a low price, they apparently found that they were all buying the same vegetables. One person said, "It's really cheap, isn't it? This is XXX yen!", And the other was surprised, "What? I was ** yen higher than that! Why?", And the rest One of them saw the receipt and noticed that he bought the cheapest one.
Now, how can you pack the bag at the lowest purchase price? Enter the number of vegetables to purchase, the number of vegetables in the bag, and the price of each vegetable, and create a program that outputs the minimum purchase price.
Input
A sequence of multiple datasets is given as input. The end of the input is indicated by two lines of zeros. Each dataset is given in the following format:
n m
p1 p2 ... pn
The first line gives the number of vegetables to buy n (1 ≤ n ≤ 1000) and the number of vegetables to put in the bag m (1 ≤ m ≤ 1000). The second line gives the price pi (10 ≤ pi ≤ 10000) for each vegetable.
The number of datasets does not exceed 100.
Output
Prints the minimum purchase price on one line for each input dataset.
Example
Input
4 2
50 40 100 80
7 3
400 300 100 700 200 600 500
0 0
Output
150
2100 | 7 | 0 | #include <cstdio>
#include <algorithm>
using namespace std;
bool comp(const int& a, const int& b) {
return a>b;
}
int n, m;
int p[1000];
int main() {
while (scanf("%d%d",&n,&m)) {
if (!n&&!m) break;
for (int i=0; i<n; i++) {
scanf("%d",&p[i]);
}
sort(p,p+n,comp);
for (int i=m-1; i<n; i+=m) {
p[i]=0;
}
int res=0;
for (int i=0; i<n; i++) {
res+=p[i];
}
printf("%d\n",res);
}
} | CPP |
p00227 Thanksgiving | As bad weather continues and vegetable prices soar, Seven-Eleven is offering customers bulk purchase sales of vegetables. The store is very busy, as you can get vegetables that are hard to find in stores at reasonable prices.
One day, a group of three good friends living in the Matsunaga housing complex bloomed with an advertisement for Seven-Eleven. Since this sale was called "Customer Thanksgiving Day", the highlight is that the cheapest vegetables in the bag are free. When I read the advertisement, it looks like the following sale.
* Up to m vegetables can be packed in one bag.
* For bags packed with m vegetables, the cheapest vegetables are free.
* Bags with less than m vegetables are not eligible for the discount.
The three went shopping at Seven Mart immediately.
When the three people who met outside the store after shopping were satisfied with the fact that they were able to buy a lot at a low price, they apparently found that they were all buying the same vegetables. One person said, "It's really cheap, isn't it? This is XXX yen!", And the other was surprised, "What? I was ** yen higher than that! Why?", And the rest One of them saw the receipt and noticed that he bought the cheapest one.
Now, how can you pack the bag at the lowest purchase price? Enter the number of vegetables to purchase, the number of vegetables in the bag, and the price of each vegetable, and create a program that outputs the minimum purchase price.
Input
A sequence of multiple datasets is given as input. The end of the input is indicated by two lines of zeros. Each dataset is given in the following format:
n m
p1 p2 ... pn
The first line gives the number of vegetables to buy n (1 ≤ n ≤ 1000) and the number of vegetables to put in the bag m (1 ≤ m ≤ 1000). The second line gives the price pi (10 ≤ pi ≤ 10000) for each vegetable.
The number of datasets does not exceed 100.
Output
Prints the minimum purchase price on one line for each input dataset.
Example
Input
4 2
50 40 100 80
7 3
400 300 100 700 200 600 500
0 0
Output
150
2100 | 7 | 0 | import java.util.Arrays;
import java.util.Scanner;
public class Main {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
while(true){
int n = sc.nextInt();
int m = sc.nextInt();
if((n|m)==0)break;
int[] a = new int[n];
int s = 0;
for(int i=0;i<n;i++){
a[i] = sc.nextInt();
s+=a[i];
}
Arrays.sort(a);
int b = 0;
for(int i=n-1;i>=0;i--){
b++;
if(b%m==0)s-=a[i];
}
System.out.println(s);
}
}
} | JAVA |
p00227 Thanksgiving | As bad weather continues and vegetable prices soar, Seven-Eleven is offering customers bulk purchase sales of vegetables. The store is very busy, as you can get vegetables that are hard to find in stores at reasonable prices.
One day, a group of three good friends living in the Matsunaga housing complex bloomed with an advertisement for Seven-Eleven. Since this sale was called "Customer Thanksgiving Day", the highlight is that the cheapest vegetables in the bag are free. When I read the advertisement, it looks like the following sale.
* Up to m vegetables can be packed in one bag.
* For bags packed with m vegetables, the cheapest vegetables are free.
* Bags with less than m vegetables are not eligible for the discount.
The three went shopping at Seven Mart immediately.
When the three people who met outside the store after shopping were satisfied with the fact that they were able to buy a lot at a low price, they apparently found that they were all buying the same vegetables. One person said, "It's really cheap, isn't it? This is XXX yen!", And the other was surprised, "What? I was ** yen higher than that! Why?", And the rest One of them saw the receipt and noticed that he bought the cheapest one.
Now, how can you pack the bag at the lowest purchase price? Enter the number of vegetables to purchase, the number of vegetables in the bag, and the price of each vegetable, and create a program that outputs the minimum purchase price.
Input
A sequence of multiple datasets is given as input. The end of the input is indicated by two lines of zeros. Each dataset is given in the following format:
n m
p1 p2 ... pn
The first line gives the number of vegetables to buy n (1 ≤ n ≤ 1000) and the number of vegetables to put in the bag m (1 ≤ m ≤ 1000). The second line gives the price pi (10 ≤ pi ≤ 10000) for each vegetable.
The number of datasets does not exceed 100.
Output
Prints the minimum purchase price on one line for each input dataset.
Example
Input
4 2
50 40 100 80
7 3
400 300 100 700 200 600 500
0 0
Output
150
2100 | 7 | 0 | while True :
n, m = map(int, input().split())
if n == 0 and m == 0 :
break
p = list(map(int, input().split()))
p.sort(reverse=True)
cst = 0
for i in range(n) :
if (i+1) % m != 0 :
cst += p[i]
print(cst)
| PYTHON3 |
p00227 Thanksgiving | As bad weather continues and vegetable prices soar, Seven-Eleven is offering customers bulk purchase sales of vegetables. The store is very busy, as you can get vegetables that are hard to find in stores at reasonable prices.
One day, a group of three good friends living in the Matsunaga housing complex bloomed with an advertisement for Seven-Eleven. Since this sale was called "Customer Thanksgiving Day", the highlight is that the cheapest vegetables in the bag are free. When I read the advertisement, it looks like the following sale.
* Up to m vegetables can be packed in one bag.
* For bags packed with m vegetables, the cheapest vegetables are free.
* Bags with less than m vegetables are not eligible for the discount.
The three went shopping at Seven Mart immediately.
When the three people who met outside the store after shopping were satisfied with the fact that they were able to buy a lot at a low price, they apparently found that they were all buying the same vegetables. One person said, "It's really cheap, isn't it? This is XXX yen!", And the other was surprised, "What? I was ** yen higher than that! Why?", And the rest One of them saw the receipt and noticed that he bought the cheapest one.
Now, how can you pack the bag at the lowest purchase price? Enter the number of vegetables to purchase, the number of vegetables in the bag, and the price of each vegetable, and create a program that outputs the minimum purchase price.
Input
A sequence of multiple datasets is given as input. The end of the input is indicated by two lines of zeros. Each dataset is given in the following format:
n m
p1 p2 ... pn
The first line gives the number of vegetables to buy n (1 ≤ n ≤ 1000) and the number of vegetables to put in the bag m (1 ≤ m ≤ 1000). The second line gives the price pi (10 ≤ pi ≤ 10000) for each vegetable.
The number of datasets does not exceed 100.
Output
Prints the minimum purchase price on one line for each input dataset.
Example
Input
4 2
50 40 100 80
7 3
400 300 100 700 200 600 500
0 0
Output
150
2100 | 7 | 0 | #include <iostream>
#include <cstdio>
#include <algorithm>
#include <functional>
using namespace std;
int p[1001];
int main(void) {
int N, M;
unsigned long long sum;
while(cin >> N >> M, N != 0 && M != 0) {
sum = 0;
for(int i = 0 ; i < N ; i++) cin >> p[i];
sort(p, p+N, greater<int>());
for(int i = M-1 ; i < N ; i+=M) p[i] = 0;
for(int i = 0 ; i < N ; i++) sum += p[i];
cout << sum << endl;
}
return 0;
} | CPP |
p00227 Thanksgiving | As bad weather continues and vegetable prices soar, Seven-Eleven is offering customers bulk purchase sales of vegetables. The store is very busy, as you can get vegetables that are hard to find in stores at reasonable prices.
One day, a group of three good friends living in the Matsunaga housing complex bloomed with an advertisement for Seven-Eleven. Since this sale was called "Customer Thanksgiving Day", the highlight is that the cheapest vegetables in the bag are free. When I read the advertisement, it looks like the following sale.
* Up to m vegetables can be packed in one bag.
* For bags packed with m vegetables, the cheapest vegetables are free.
* Bags with less than m vegetables are not eligible for the discount.
The three went shopping at Seven Mart immediately.
When the three people who met outside the store after shopping were satisfied with the fact that they were able to buy a lot at a low price, they apparently found that they were all buying the same vegetables. One person said, "It's really cheap, isn't it? This is XXX yen!", And the other was surprised, "What? I was ** yen higher than that! Why?", And the rest One of them saw the receipt and noticed that he bought the cheapest one.
Now, how can you pack the bag at the lowest purchase price? Enter the number of vegetables to purchase, the number of vegetables in the bag, and the price of each vegetable, and create a program that outputs the minimum purchase price.
Input
A sequence of multiple datasets is given as input. The end of the input is indicated by two lines of zeros. Each dataset is given in the following format:
n m
p1 p2 ... pn
The first line gives the number of vegetables to buy n (1 ≤ n ≤ 1000) and the number of vegetables to put in the bag m (1 ≤ m ≤ 1000). The second line gives the price pi (10 ≤ pi ≤ 10000) for each vegetable.
The number of datasets does not exceed 100.
Output
Prints the minimum purchase price on one line for each input dataset.
Example
Input
4 2
50 40 100 80
7 3
400 300 100 700 200 600 500
0 0
Output
150
2100 | 7 | 0 | #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> vegetable(n,0);
for(int i = 0; i < n; ++i){
std::cin >> vegetable[i];
}
std::sort(vegetable.begin(), vegetable.end(), std::greater<int>());
int price = 0;
for(int i = 0; i < n; ++i){
if((i % m) != (m - 1)){
price += vegetable.at(i);
}
}
std::cout << price << std::endl;
}
return 0;
} | CPP |
p00227 Thanksgiving | As bad weather continues and vegetable prices soar, Seven-Eleven is offering customers bulk purchase sales of vegetables. The store is very busy, as you can get vegetables that are hard to find in stores at reasonable prices.
One day, a group of three good friends living in the Matsunaga housing complex bloomed with an advertisement for Seven-Eleven. Since this sale was called "Customer Thanksgiving Day", the highlight is that the cheapest vegetables in the bag are free. When I read the advertisement, it looks like the following sale.
* Up to m vegetables can be packed in one bag.
* For bags packed with m vegetables, the cheapest vegetables are free.
* Bags with less than m vegetables are not eligible for the discount.
The three went shopping at Seven Mart immediately.
When the three people who met outside the store after shopping were satisfied with the fact that they were able to buy a lot at a low price, they apparently found that they were all buying the same vegetables. One person said, "It's really cheap, isn't it? This is XXX yen!", And the other was surprised, "What? I was ** yen higher than that! Why?", And the rest One of them saw the receipt and noticed that he bought the cheapest one.
Now, how can you pack the bag at the lowest purchase price? Enter the number of vegetables to purchase, the number of vegetables in the bag, and the price of each vegetable, and create a program that outputs the minimum purchase price.
Input
A sequence of multiple datasets is given as input. The end of the input is indicated by two lines of zeros. Each dataset is given in the following format:
n m
p1 p2 ... pn
The first line gives the number of vegetables to buy n (1 ≤ n ≤ 1000) and the number of vegetables to put in the bag m (1 ≤ m ≤ 1000). The second line gives the price pi (10 ≤ pi ≤ 10000) for each vegetable.
The number of datasets does not exceed 100.
Output
Prints the minimum purchase price on one line for each input dataset.
Example
Input
4 2
50 40 100 80
7 3
400 300 100 700 200 600 500
0 0
Output
150
2100 | 7 | 0 | #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;
} | CPP |
p00227 Thanksgiving | As bad weather continues and vegetable prices soar, Seven-Eleven is offering customers bulk purchase sales of vegetables. The store is very busy, as you can get vegetables that are hard to find in stores at reasonable prices.
One day, a group of three good friends living in the Matsunaga housing complex bloomed with an advertisement for Seven-Eleven. Since this sale was called "Customer Thanksgiving Day", the highlight is that the cheapest vegetables in the bag are free. When I read the advertisement, it looks like the following sale.
* Up to m vegetables can be packed in one bag.
* For bags packed with m vegetables, the cheapest vegetables are free.
* Bags with less than m vegetables are not eligible for the discount.
The three went shopping at Seven Mart immediately.
When the three people who met outside the store after shopping were satisfied with the fact that they were able to buy a lot at a low price, they apparently found that they were all buying the same vegetables. One person said, "It's really cheap, isn't it? This is XXX yen!", And the other was surprised, "What? I was ** yen higher than that! Why?", And the rest One of them saw the receipt and noticed that he bought the cheapest one.
Now, how can you pack the bag at the lowest purchase price? Enter the number of vegetables to purchase, the number of vegetables in the bag, and the price of each vegetable, and create a program that outputs the minimum purchase price.
Input
A sequence of multiple datasets is given as input. The end of the input is indicated by two lines of zeros. Each dataset is given in the following format:
n m
p1 p2 ... pn
The first line gives the number of vegetables to buy n (1 ≤ n ≤ 1000) and the number of vegetables to put in the bag m (1 ≤ m ≤ 1000). The second line gives the price pi (10 ≤ pi ≤ 10000) for each vegetable.
The number of datasets does not exceed 100.
Output
Prints the minimum purchase price on one line for each input dataset.
Example
Input
4 2
50 40 100 80
7 3
400 300 100 700 200 600 500
0 0
Output
150
2100 | 7 | 0 | #include<bits/stdc++.h>
using namespace std;
#define MAX 1000
int 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;
}
} | CPP |
p00227 Thanksgiving | As bad weather continues and vegetable prices soar, Seven-Eleven is offering customers bulk purchase sales of vegetables. The store is very busy, as you can get vegetables that are hard to find in stores at reasonable prices.
One day, a group of three good friends living in the Matsunaga housing complex bloomed with an advertisement for Seven-Eleven. Since this sale was called "Customer Thanksgiving Day", the highlight is that the cheapest vegetables in the bag are free. When I read the advertisement, it looks like the following sale.
* Up to m vegetables can be packed in one bag.
* For bags packed with m vegetables, the cheapest vegetables are free.
* Bags with less than m vegetables are not eligible for the discount.
The three went shopping at Seven Mart immediately.
When the three people who met outside the store after shopping were satisfied with the fact that they were able to buy a lot at a low price, they apparently found that they were all buying the same vegetables. One person said, "It's really cheap, isn't it? This is XXX yen!", And the other was surprised, "What? I was ** yen higher than that! Why?", And the rest One of them saw the receipt and noticed that he bought the cheapest one.
Now, how can you pack the bag at the lowest purchase price? Enter the number of vegetables to purchase, the number of vegetables in the bag, and the price of each vegetable, and create a program that outputs the minimum purchase price.
Input
A sequence of multiple datasets is given as input. The end of the input is indicated by two lines of zeros. Each dataset is given in the following format:
n m
p1 p2 ... pn
The first line gives the number of vegetables to buy n (1 ≤ n ≤ 1000) and the number of vegetables to put in the bag m (1 ≤ m ≤ 1000). The second line gives the price pi (10 ≤ pi ≤ 10000) for each vegetable.
The number of datasets does not exceed 100.
Output
Prints the minimum purchase price on one line for each input dataset.
Example
Input
4 2
50 40 100 80
7 3
400 300 100 700 200 600 500
0 0
Output
150
2100 | 7 | 0 | #include <iostream>
#include <vector>
#include <string>
#include <queue>
#include <map>
#include <algorithm>
#define INF 10000000
using namespace std;
typedef pair<int,int> P;
int n,m;
int p[1000];
int main(){
while(1){
cin >> n >> m;
if(!n&&!m){
return 0;
}
for(int i=0;i<n;i++){
cin >> p[i];
}
sort(p,p+n);
int sum=0;
for(int i=1;i<=n;i++){
if(i%m!=0){
sum += p[n-i];
}
}
cout << sum << endl;
}
} | CPP |
p00227 Thanksgiving | As bad weather continues and vegetable prices soar, Seven-Eleven is offering customers bulk purchase sales of vegetables. The store is very busy, as you can get vegetables that are hard to find in stores at reasonable prices.
One day, a group of three good friends living in the Matsunaga housing complex bloomed with an advertisement for Seven-Eleven. Since this sale was called "Customer Thanksgiving Day", the highlight is that the cheapest vegetables in the bag are free. When I read the advertisement, it looks like the following sale.
* Up to m vegetables can be packed in one bag.
* For bags packed with m vegetables, the cheapest vegetables are free.
* Bags with less than m vegetables are not eligible for the discount.
The three went shopping at Seven Mart immediately.
When the three people who met outside the store after shopping were satisfied with the fact that they were able to buy a lot at a low price, they apparently found that they were all buying the same vegetables. One person said, "It's really cheap, isn't it? This is XXX yen!", And the other was surprised, "What? I was ** yen higher than that! Why?", And the rest One of them saw the receipt and noticed that he bought the cheapest one.
Now, how can you pack the bag at the lowest purchase price? Enter the number of vegetables to purchase, the number of vegetables in the bag, and the price of each vegetable, and create a program that outputs the minimum purchase price.
Input
A sequence of multiple datasets is given as input. The end of the input is indicated by two lines of zeros. Each dataset is given in the following format:
n m
p1 p2 ... pn
The first line gives the number of vegetables to buy n (1 ≤ n ≤ 1000) and the number of vegetables to put in the bag m (1 ≤ m ≤ 1000). The second line gives the price pi (10 ≤ pi ≤ 10000) for each vegetable.
The number of datasets does not exceed 100.
Output
Prints the minimum purchase price on one line for each input dataset.
Example
Input
4 2
50 40 100 80
7 3
400 300 100 700 200 600 500
0 0
Output
150
2100 | 7 | 0 | #include <iostream>
#include <algorithm>
#include <queue>
#include <vector>
#include <functional>
#include<cstdio>
using namespace std;
int main(void){
int n,m;
int a;
while(1){
cin >> n >> m;
if(n==0 && m==0)break;
int ans=0;
vector<int> num;
for(a=0;a<n;a++){
int nn;
scanf("%d",&nn);
num.push_back(nn);
}
sort(num.begin(),num.end(), greater<int>() );
for(a=0;a<n;a++){
ans+=num[a];
}
for(a=1*m-1;a<n;a+=m){
ans-=num[a];
}
cout << ans << endl;
}
return 0;
} | CPP |
p00227 Thanksgiving | As bad weather continues and vegetable prices soar, Seven-Eleven is offering customers bulk purchase sales of vegetables. The store is very busy, as you can get vegetables that are hard to find in stores at reasonable prices.
One day, a group of three good friends living in the Matsunaga housing complex bloomed with an advertisement for Seven-Eleven. Since this sale was called "Customer Thanksgiving Day", the highlight is that the cheapest vegetables in the bag are free. When I read the advertisement, it looks like the following sale.
* Up to m vegetables can be packed in one bag.
* For bags packed with m vegetables, the cheapest vegetables are free.
* Bags with less than m vegetables are not eligible for the discount.
The three went shopping at Seven Mart immediately.
When the three people who met outside the store after shopping were satisfied with the fact that they were able to buy a lot at a low price, they apparently found that they were all buying the same vegetables. One person said, "It's really cheap, isn't it? This is XXX yen!", And the other was surprised, "What? I was ** yen higher than that! Why?", And the rest One of them saw the receipt and noticed that he bought the cheapest one.
Now, how can you pack the bag at the lowest purchase price? Enter the number of vegetables to purchase, the number of vegetables in the bag, and the price of each vegetable, and create a program that outputs the minimum purchase price.
Input
A sequence of multiple datasets is given as input. The end of the input is indicated by two lines of zeros. Each dataset is given in the following format:
n m
p1 p2 ... pn
The first line gives the number of vegetables to buy n (1 ≤ n ≤ 1000) and the number of vegetables to put in the bag m (1 ≤ m ≤ 1000). The second line gives the price pi (10 ≤ pi ≤ 10000) for each vegetable.
The number of datasets does not exceed 100.
Output
Prints the minimum purchase price on one line for each input dataset.
Example
Input
4 2
50 40 100 80
7 3
400 300 100 700 200 600 500
0 0
Output
150
2100 | 7 | 0 | import java.util.*;
public class Main
{
public static void main(String[] args)
{
Scanner stdIn = new Scanner(System.in);
while(stdIn.hasNext())
{
int n = stdIn.nextInt();
int m = stdIn.nextInt();
if(n == 0 && m == 0)
{
break;
}
List<Integer> list = new ArrayList<Integer>();
for(int i = 0; i < n; ++i)
{
int price = stdIn.nextInt();
list.add(price);
}
Collections.sort(list);
int count = 1;
int sum = 0;
for(int i = list.size() - 1; i >= 0; --i)
{
if(count == m)
{
count = 1;
continue;
}
sum += list.get(i);
++count;
}
System.out.println(sum);
}
}
} | JAVA |
p00227 Thanksgiving | As bad weather continues and vegetable prices soar, Seven-Eleven is offering customers bulk purchase sales of vegetables. The store is very busy, as you can get vegetables that are hard to find in stores at reasonable prices.
One day, a group of three good friends living in the Matsunaga housing complex bloomed with an advertisement for Seven-Eleven. Since this sale was called "Customer Thanksgiving Day", the highlight is that the cheapest vegetables in the bag are free. When I read the advertisement, it looks like the following sale.
* Up to m vegetables can be packed in one bag.
* For bags packed with m vegetables, the cheapest vegetables are free.
* Bags with less than m vegetables are not eligible for the discount.
The three went shopping at Seven Mart immediately.
When the three people who met outside the store after shopping were satisfied with the fact that they were able to buy a lot at a low price, they apparently found that they were all buying the same vegetables. One person said, "It's really cheap, isn't it? This is XXX yen!", And the other was surprised, "What? I was ** yen higher than that! Why?", And the rest One of them saw the receipt and noticed that he bought the cheapest one.
Now, how can you pack the bag at the lowest purchase price? Enter the number of vegetables to purchase, the number of vegetables in the bag, and the price of each vegetable, and create a program that outputs the minimum purchase price.
Input
A sequence of multiple datasets is given as input. The end of the input is indicated by two lines of zeros. Each dataset is given in the following format:
n m
p1 p2 ... pn
The first line gives the number of vegetables to buy n (1 ≤ n ≤ 1000) and the number of vegetables to put in the bag m (1 ≤ m ≤ 1000). The second line gives the price pi (10 ≤ pi ≤ 10000) for each vegetable.
The number of datasets does not exceed 100.
Output
Prints the minimum purchase price on one line for each input dataset.
Example
Input
4 2
50 40 100 80
7 3
400 300 100 700 200 600 500
0 0
Output
150
2100 | 7 | 0 | import java.util.Arrays;
import java.util.Collections;
import java.util.Scanner;
public class Main{
public static void main(String[] args) {
Scanner s = new Scanner(System.in);
while(s.hasNextLine()) {
int purchaceCnt = s.nextInt();
int canPackCnt = s.nextInt();
if(purchaceCnt==0 && canPackCnt==0)
return;
s.nextLine();
String[] values = s.nextLine().split(" ");
Integer[] value = new Integer[values.length];
for(int i=0 ; i<values.length ; i++){
value[i] = new Integer(values[i]);
}
System.out.println(solve(purchaceCnt, canPackCnt, value));
}
}
public static int solve(int purchaceCnt, int canPackCnt, Integer[] values) {
int value = 0;
int cnt=0;
if(purchaceCnt >= canPackCnt){//無料にできる場合
Arrays.sort(values, Collections.reverseOrder());
for(int i=0 ; i<purchaceCnt ; i++) {
cnt++;
if(cnt==canPackCnt) {
cnt = 0;
}else {
value += values[i].intValue();
}
}
}else{
Arrays.sort(values);
for(int i=0 ; i<purchaceCnt ; i++) {
value += values[i].intValue();
}
}
return value;
}
} | JAVA |
p00227 Thanksgiving | As bad weather continues and vegetable prices soar, Seven-Eleven is offering customers bulk purchase sales of vegetables. The store is very busy, as you can get vegetables that are hard to find in stores at reasonable prices.
One day, a group of three good friends living in the Matsunaga housing complex bloomed with an advertisement for Seven-Eleven. Since this sale was called "Customer Thanksgiving Day", the highlight is that the cheapest vegetables in the bag are free. When I read the advertisement, it looks like the following sale.
* Up to m vegetables can be packed in one bag.
* For bags packed with m vegetables, the cheapest vegetables are free.
* Bags with less than m vegetables are not eligible for the discount.
The three went shopping at Seven Mart immediately.
When the three people who met outside the store after shopping were satisfied with the fact that they were able to buy a lot at a low price, they apparently found that they were all buying the same vegetables. One person said, "It's really cheap, isn't it? This is XXX yen!", And the other was surprised, "What? I was ** yen higher than that! Why?", And the rest One of them saw the receipt and noticed that he bought the cheapest one.
Now, how can you pack the bag at the lowest purchase price? Enter the number of vegetables to purchase, the number of vegetables in the bag, and the price of each vegetable, and create a program that outputs the minimum purchase price.
Input
A sequence of multiple datasets is given as input. The end of the input is indicated by two lines of zeros. Each dataset is given in the following format:
n m
p1 p2 ... pn
The first line gives the number of vegetables to buy n (1 ≤ n ≤ 1000) and the number of vegetables to put in the bag m (1 ≤ m ≤ 1000). The second line gives the price pi (10 ≤ pi ≤ 10000) for each vegetable.
The number of datasets does not exceed 100.
Output
Prints the minimum purchase price on one line for each input dataset.
Example
Input
4 2
50 40 100 80
7 3
400 300 100 700 200 600 500
0 0
Output
150
2100 | 7 | 0 | #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;
}
| CPP |
p00227 Thanksgiving | As bad weather continues and vegetable prices soar, Seven-Eleven is offering customers bulk purchase sales of vegetables. The store is very busy, as you can get vegetables that are hard to find in stores at reasonable prices.
One day, a group of three good friends living in the Matsunaga housing complex bloomed with an advertisement for Seven-Eleven. Since this sale was called "Customer Thanksgiving Day", the highlight is that the cheapest vegetables in the bag are free. When I read the advertisement, it looks like the following sale.
* Up to m vegetables can be packed in one bag.
* For bags packed with m vegetables, the cheapest vegetables are free.
* Bags with less than m vegetables are not eligible for the discount.
The three went shopping at Seven Mart immediately.
When the three people who met outside the store after shopping were satisfied with the fact that they were able to buy a lot at a low price, they apparently found that they were all buying the same vegetables. One person said, "It's really cheap, isn't it? This is XXX yen!", And the other was surprised, "What? I was ** yen higher than that! Why?", And the rest One of them saw the receipt and noticed that he bought the cheapest one.
Now, how can you pack the bag at the lowest purchase price? Enter the number of vegetables to purchase, the number of vegetables in the bag, and the price of each vegetable, and create a program that outputs the minimum purchase price.
Input
A sequence of multiple datasets is given as input. The end of the input is indicated by two lines of zeros. Each dataset is given in the following format:
n m
p1 p2 ... pn
The first line gives the number of vegetables to buy n (1 ≤ n ≤ 1000) and the number of vegetables to put in the bag m (1 ≤ m ≤ 1000). The second line gives the price pi (10 ≤ pi ≤ 10000) for each vegetable.
The number of datasets does not exceed 100.
Output
Prints the minimum purchase price on one line for each input dataset.
Example
Input
4 2
50 40 100 80
7 3
400 300 100 700 200 600 500
0 0
Output
150
2100 | 7 | 0 | #include <iostream>
#include <vector>
#include <algorithm>
#include <numeric>
int main(){
int n, m;
while(std::cin >> n >> m){
//n及びmが0ならば終了
if(n == 0 && m == 0){
return 0;
}
std::vector<int> p(n);
for(int i = 0; i < n; ++i){
std::cin >> p[i];
}
std::sort(p.begin(), p.end(), std::greater<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;
} | CPP |
p00227 Thanksgiving | As bad weather continues and vegetable prices soar, Seven-Eleven is offering customers bulk purchase sales of vegetables. The store is very busy, as you can get vegetables that are hard to find in stores at reasonable prices.
One day, a group of three good friends living in the Matsunaga housing complex bloomed with an advertisement for Seven-Eleven. Since this sale was called "Customer Thanksgiving Day", the highlight is that the cheapest vegetables in the bag are free. When I read the advertisement, it looks like the following sale.
* Up to m vegetables can be packed in one bag.
* For bags packed with m vegetables, the cheapest vegetables are free.
* Bags with less than m vegetables are not eligible for the discount.
The three went shopping at Seven Mart immediately.
When the three people who met outside the store after shopping were satisfied with the fact that they were able to buy a lot at a low price, they apparently found that they were all buying the same vegetables. One person said, "It's really cheap, isn't it? This is XXX yen!", And the other was surprised, "What? I was ** yen higher than that! Why?", And the rest One of them saw the receipt and noticed that he bought the cheapest one.
Now, how can you pack the bag at the lowest purchase price? Enter the number of vegetables to purchase, the number of vegetables in the bag, and the price of each vegetable, and create a program that outputs the minimum purchase price.
Input
A sequence of multiple datasets is given as input. The end of the input is indicated by two lines of zeros. Each dataset is given in the following format:
n m
p1 p2 ... pn
The first line gives the number of vegetables to buy n (1 ≤ n ≤ 1000) and the number of vegetables to put in the bag m (1 ≤ m ≤ 1000). The second line gives the price pi (10 ≤ pi ≤ 10000) for each vegetable.
The number of datasets does not exceed 100.
Output
Prints the minimum purchase price on one line for each input dataset.
Example
Input
4 2
50 40 100 80
7 3
400 300 100 700 200 600 500
0 0
Output
150
2100 | 7 | 0 | #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 < n && j < i + m; ++j)
ans += p[j];
if(i + m <= n)
ans -= p[i + m - 1];
}
cout << ans << endl;
}
return 0;
} | CPP |
p00227 Thanksgiving | As bad weather continues and vegetable prices soar, Seven-Eleven is offering customers bulk purchase sales of vegetables. The store is very busy, as you can get vegetables that are hard to find in stores at reasonable prices.
One day, a group of three good friends living in the Matsunaga housing complex bloomed with an advertisement for Seven-Eleven. Since this sale was called "Customer Thanksgiving Day", the highlight is that the cheapest vegetables in the bag are free. When I read the advertisement, it looks like the following sale.
* Up to m vegetables can be packed in one bag.
* For bags packed with m vegetables, the cheapest vegetables are free.
* Bags with less than m vegetables are not eligible for the discount.
The three went shopping at Seven Mart immediately.
When the three people who met outside the store after shopping were satisfied with the fact that they were able to buy a lot at a low price, they apparently found that they were all buying the same vegetables. One person said, "It's really cheap, isn't it? This is XXX yen!", And the other was surprised, "What? I was ** yen higher than that! Why?", And the rest One of them saw the receipt and noticed that he bought the cheapest one.
Now, how can you pack the bag at the lowest purchase price? Enter the number of vegetables to purchase, the number of vegetables in the bag, and the price of each vegetable, and create a program that outputs the minimum purchase price.
Input
A sequence of multiple datasets is given as input. The end of the input is indicated by two lines of zeros. Each dataset is given in the following format:
n m
p1 p2 ... pn
The first line gives the number of vegetables to buy n (1 ≤ n ≤ 1000) and the number of vegetables to put in the bag m (1 ≤ m ≤ 1000). The second line gives the price pi (10 ≤ pi ≤ 10000) for each vegetable.
The number of datasets does not exceed 100.
Output
Prints the minimum purchase price on one line for each input dataset.
Example
Input
4 2
50 40 100 80
7 3
400 300 100 700 200 600 500
0 0
Output
150
2100 | 7 | 0 | #include <iostream>
#include <algorithm>
using namespace std;
int main(){
int n,m;
int a[1111];
int x=-1;
while(1){
x=-1;
int ans=0;
cin >> n >> m;//nは購入数 mは最大数
if(n==0 && m==0)break;
for(int i=0;i<n;i++){
cin >> a[i];
ans+=a[i];
}
sort(a,a+n,greater<int>());
while(n>=m){
x+=m;
ans-=a[x];
n-=m;
}
cout << ans << endl;
}
} | CPP |
p00227 Thanksgiving | As bad weather continues and vegetable prices soar, Seven-Eleven is offering customers bulk purchase sales of vegetables. The store is very busy, as you can get vegetables that are hard to find in stores at reasonable prices.
One day, a group of three good friends living in the Matsunaga housing complex bloomed with an advertisement for Seven-Eleven. Since this sale was called "Customer Thanksgiving Day", the highlight is that the cheapest vegetables in the bag are free. When I read the advertisement, it looks like the following sale.
* Up to m vegetables can be packed in one bag.
* For bags packed with m vegetables, the cheapest vegetables are free.
* Bags with less than m vegetables are not eligible for the discount.
The three went shopping at Seven Mart immediately.
When the three people who met outside the store after shopping were satisfied with the fact that they were able to buy a lot at a low price, they apparently found that they were all buying the same vegetables. One person said, "It's really cheap, isn't it? This is XXX yen!", And the other was surprised, "What? I was ** yen higher than that! Why?", And the rest One of them saw the receipt and noticed that he bought the cheapest one.
Now, how can you pack the bag at the lowest purchase price? Enter the number of vegetables to purchase, the number of vegetables in the bag, and the price of each vegetable, and create a program that outputs the minimum purchase price.
Input
A sequence of multiple datasets is given as input. The end of the input is indicated by two lines of zeros. Each dataset is given in the following format:
n m
p1 p2 ... pn
The first line gives the number of vegetables to buy n (1 ≤ n ≤ 1000) and the number of vegetables to put in the bag m (1 ≤ m ≤ 1000). The second line gives the price pi (10 ≤ pi ≤ 10000) for each vegetable.
The number of datasets does not exceed 100.
Output
Prints the minimum purchase price on one line for each input dataset.
Example
Input
4 2
50 40 100 80
7 3
400 300 100 700 200 600 500
0 0
Output
150
2100 | 7 | 0 | #include <algorithm>
#include <iostream>
using namespace std;
int main() {
for (;;) {
int n, m, ps[1000];
cin >> n >> m;
if (!n && !m) return 0;
int r = 0;
for (int i = 0; i < n; i++)
cin >> ps[i];
sort(ps, ps+n);
for (int i = 0; i < n; i++)
r += ps[i];
for (int i = n % m; i < n; i += m)
r -= ps[i];
cout << r << endl;
}
} | CPP |
p00227 Thanksgiving | As bad weather continues and vegetable prices soar, Seven-Eleven is offering customers bulk purchase sales of vegetables. The store is very busy, as you can get vegetables that are hard to find in stores at reasonable prices.
One day, a group of three good friends living in the Matsunaga housing complex bloomed with an advertisement for Seven-Eleven. Since this sale was called "Customer Thanksgiving Day", the highlight is that the cheapest vegetables in the bag are free. When I read the advertisement, it looks like the following sale.
* Up to m vegetables can be packed in one bag.
* For bags packed with m vegetables, the cheapest vegetables are free.
* Bags with less than m vegetables are not eligible for the discount.
The three went shopping at Seven Mart immediately.
When the three people who met outside the store after shopping were satisfied with the fact that they were able to buy a lot at a low price, they apparently found that they were all buying the same vegetables. One person said, "It's really cheap, isn't it? This is XXX yen!", And the other was surprised, "What? I was ** yen higher than that! Why?", And the rest One of them saw the receipt and noticed that he bought the cheapest one.
Now, how can you pack the bag at the lowest purchase price? Enter the number of vegetables to purchase, the number of vegetables in the bag, and the price of each vegetable, and create a program that outputs the minimum purchase price.
Input
A sequence of multiple datasets is given as input. The end of the input is indicated by two lines of zeros. Each dataset is given in the following format:
n m
p1 p2 ... pn
The first line gives the number of vegetables to buy n (1 ≤ n ≤ 1000) and the number of vegetables to put in the bag m (1 ≤ m ≤ 1000). The second line gives the price pi (10 ≤ pi ≤ 10000) for each vegetable.
The number of datasets does not exceed 100.
Output
Prints the minimum purchase price on one line for each input dataset.
Example
Input
4 2
50 40 100 80
7 3
400 300 100 700 200 600 500
0 0
Output
150
2100 | 7 | 0 | #include <iostream>
#include <algorithm>
#include <functional>
using namespace std;
int main(){
int n,m,fig[1001];
while(cin >> n >> m,n||m){
int ans = 0;
for(int i=0;i<n;i++) cin >> fig[i];
sort(fig,fig+n,greater<int>());
for(int i=0;i<(n/m)*m;i++){
if((i+1) % m) ans += fig[i];
}
for(int i=n-1,j=0;j<(n%m);i--,j++) ans += fig[i];
fill(fig,fig+1001,0);
cout << ans << endl;
}
} | CPP |
p00227 Thanksgiving | As bad weather continues and vegetable prices soar, Seven-Eleven is offering customers bulk purchase sales of vegetables. The store is very busy, as you can get vegetables that are hard to find in stores at reasonable prices.
One day, a group of three good friends living in the Matsunaga housing complex bloomed with an advertisement for Seven-Eleven. Since this sale was called "Customer Thanksgiving Day", the highlight is that the cheapest vegetables in the bag are free. When I read the advertisement, it looks like the following sale.
* Up to m vegetables can be packed in one bag.
* For bags packed with m vegetables, the cheapest vegetables are free.
* Bags with less than m vegetables are not eligible for the discount.
The three went shopping at Seven Mart immediately.
When the three people who met outside the store after shopping were satisfied with the fact that they were able to buy a lot at a low price, they apparently found that they were all buying the same vegetables. One person said, "It's really cheap, isn't it? This is XXX yen!", And the other was surprised, "What? I was ** yen higher than that! Why?", And the rest One of them saw the receipt and noticed that he bought the cheapest one.
Now, how can you pack the bag at the lowest purchase price? Enter the number of vegetables to purchase, the number of vegetables in the bag, and the price of each vegetable, and create a program that outputs the minimum purchase price.
Input
A sequence of multiple datasets is given as input. The end of the input is indicated by two lines of zeros. Each dataset is given in the following format:
n m
p1 p2 ... pn
The first line gives the number of vegetables to buy n (1 ≤ n ≤ 1000) and the number of vegetables to put in the bag m (1 ≤ m ≤ 1000). The second line gives the price pi (10 ≤ pi ≤ 10000) for each vegetable.
The number of datasets does not exceed 100.
Output
Prints the minimum purchase price on one line for each input dataset.
Example
Input
4 2
50 40 100 80
7 3
400 300 100 700 200 600 500
0 0
Output
150
2100 | 7 | 0 | #include<iostream>
using namespace std;
int main(){
while(1){
int ans=0,n,m,p[1001]={};
cin>>n>>m;
if(n==0 && 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;
ans+=p[i];
}
cout<<ans<<endl;
}
return 0;
} | CPP |
p00227 Thanksgiving | As bad weather continues and vegetable prices soar, Seven-Eleven is offering customers bulk purchase sales of vegetables. The store is very busy, as you can get vegetables that are hard to find in stores at reasonable prices.
One day, a group of three good friends living in the Matsunaga housing complex bloomed with an advertisement for Seven-Eleven. Since this sale was called "Customer Thanksgiving Day", the highlight is that the cheapest vegetables in the bag are free. When I read the advertisement, it looks like the following sale.
* Up to m vegetables can be packed in one bag.
* For bags packed with m vegetables, the cheapest vegetables are free.
* Bags with less than m vegetables are not eligible for the discount.
The three went shopping at Seven Mart immediately.
When the three people who met outside the store after shopping were satisfied with the fact that they were able to buy a lot at a low price, they apparently found that they were all buying the same vegetables. One person said, "It's really cheap, isn't it? This is XXX yen!", And the other was surprised, "What? I was ** yen higher than that! Why?", And the rest One of them saw the receipt and noticed that he bought the cheapest one.
Now, how can you pack the bag at the lowest purchase price? Enter the number of vegetables to purchase, the number of vegetables in the bag, and the price of each vegetable, and create a program that outputs the minimum purchase price.
Input
A sequence of multiple datasets is given as input. The end of the input is indicated by two lines of zeros. Each dataset is given in the following format:
n m
p1 p2 ... pn
The first line gives the number of vegetables to buy n (1 ≤ n ≤ 1000) and the number of vegetables to put in the bag m (1 ≤ m ≤ 1000). The second line gives the price pi (10 ≤ pi ≤ 10000) for each vegetable.
The number of datasets does not exceed 100.
Output
Prints the minimum purchase price on one line for each input dataset.
Example
Input
4 2
50 40 100 80
7 3
400 300 100 700 200 600 500
0 0
Output
150
2100 | 7 | 0 | #include <iostream>
#include <algorithm>
#include <functional>
#define rep2(x,from,to) for(int x=(from);(x)<(to);(x)++)
#define rep(x,to) rep2(x,0,to)
using namespace std;
int main(){
int m,n,p;
while(cin >> m >> n, (m||n)) {
int p[10000];
rep(i,m) {
cin >> p[i];
}
sort(p,p+m,greater<int>());
int sum = 0;
rep(i,m) {
if(i%n!=n-1) sum += p[i];
}
cout << sum << endl;
}
} | CPP |
p00227 Thanksgiving | As bad weather continues and vegetable prices soar, Seven-Eleven is offering customers bulk purchase sales of vegetables. The store is very busy, as you can get vegetables that are hard to find in stores at reasonable prices.
One day, a group of three good friends living in the Matsunaga housing complex bloomed with an advertisement for Seven-Eleven. Since this sale was called "Customer Thanksgiving Day", the highlight is that the cheapest vegetables in the bag are free. When I read the advertisement, it looks like the following sale.
* Up to m vegetables can be packed in one bag.
* For bags packed with m vegetables, the cheapest vegetables are free.
* Bags with less than m vegetables are not eligible for the discount.
The three went shopping at Seven Mart immediately.
When the three people who met outside the store after shopping were satisfied with the fact that they were able to buy a lot at a low price, they apparently found that they were all buying the same vegetables. One person said, "It's really cheap, isn't it? This is XXX yen!", And the other was surprised, "What? I was ** yen higher than that! Why?", And the rest One of them saw the receipt and noticed that he bought the cheapest one.
Now, how can you pack the bag at the lowest purchase price? Enter the number of vegetables to purchase, the number of vegetables in the bag, and the price of each vegetable, and create a program that outputs the minimum purchase price.
Input
A sequence of multiple datasets is given as input. The end of the input is indicated by two lines of zeros. Each dataset is given in the following format:
n m
p1 p2 ... pn
The first line gives the number of vegetables to buy n (1 ≤ n ≤ 1000) and the number of vegetables to put in the bag m (1 ≤ m ≤ 1000). The second line gives the price pi (10 ≤ pi ≤ 10000) for each vegetable.
The number of datasets does not exceed 100.
Output
Prints the minimum purchase price on one line for each input dataset.
Example
Input
4 2
50 40 100 80
7 3
400 300 100 700 200 600 500
0 0
Output
150
2100 | 7 | 0 | #include<iostream>
#include<vector>
#include<algorithm>
using namespace std;
int main(void){
int n,m;
while(cin >> n >> m,m+n){
vector<int> ps(n);
for(int i = 0 ; i < n ; i ++){
cin >> ps[i];
}
sort(ps.begin(),ps.end(),greater<int>());
int ans = 0;
for(int i = 0 ; i < n ; i ++){
if((i+1)% m != 0){
ans += ps[i];
}
}
cout << ans << endl;
}
} | CPP |
p00227 Thanksgiving | As bad weather continues and vegetable prices soar, Seven-Eleven is offering customers bulk purchase sales of vegetables. The store is very busy, as you can get vegetables that are hard to find in stores at reasonable prices.
One day, a group of three good friends living in the Matsunaga housing complex bloomed with an advertisement for Seven-Eleven. Since this sale was called "Customer Thanksgiving Day", the highlight is that the cheapest vegetables in the bag are free. When I read the advertisement, it looks like the following sale.
* Up to m vegetables can be packed in one bag.
* For bags packed with m vegetables, the cheapest vegetables are free.
* Bags with less than m vegetables are not eligible for the discount.
The three went shopping at Seven Mart immediately.
When the three people who met outside the store after shopping were satisfied with the fact that they were able to buy a lot at a low price, they apparently found that they were all buying the same vegetables. One person said, "It's really cheap, isn't it? This is XXX yen!", And the other was surprised, "What? I was ** yen higher than that! Why?", And the rest One of them saw the receipt and noticed that he bought the cheapest one.
Now, how can you pack the bag at the lowest purchase price? Enter the number of vegetables to purchase, the number of vegetables in the bag, and the price of each vegetable, and create a program that outputs the minimum purchase price.
Input
A sequence of multiple datasets is given as input. The end of the input is indicated by two lines of zeros. Each dataset is given in the following format:
n m
p1 p2 ... pn
The first line gives the number of vegetables to buy n (1 ≤ n ≤ 1000) and the number of vegetables to put in the bag m (1 ≤ m ≤ 1000). The second line gives the price pi (10 ≤ pi ≤ 10000) for each vegetable.
The number of datasets does not exceed 100.
Output
Prints the minimum purchase price on one line for each input dataset.
Example
Input
4 2
50 40 100 80
7 3
400 300 100 700 200 600 500
0 0
Output
150
2100 | 7 | 0 | while True:
n, m = map(int, raw_input().split())
if n == m == 0: break
data = map(int, raw_input().split())
total = [p for i,p in enumerate(sorted(data, reverse=True)) if (i+1)%m != 0]
print sum(total) | PYTHON |
p00227 Thanksgiving | As bad weather continues and vegetable prices soar, Seven-Eleven is offering customers bulk purchase sales of vegetables. The store is very busy, as you can get vegetables that are hard to find in stores at reasonable prices.
One day, a group of three good friends living in the Matsunaga housing complex bloomed with an advertisement for Seven-Eleven. Since this sale was called "Customer Thanksgiving Day", the highlight is that the cheapest vegetables in the bag are free. When I read the advertisement, it looks like the following sale.
* Up to m vegetables can be packed in one bag.
* For bags packed with m vegetables, the cheapest vegetables are free.
* Bags with less than m vegetables are not eligible for the discount.
The three went shopping at Seven Mart immediately.
When the three people who met outside the store after shopping were satisfied with the fact that they were able to buy a lot at a low price, they apparently found that they were all buying the same vegetables. One person said, "It's really cheap, isn't it? This is XXX yen!", And the other was surprised, "What? I was ** yen higher than that! Why?", And the rest One of them saw the receipt and noticed that he bought the cheapest one.
Now, how can you pack the bag at the lowest purchase price? Enter the number of vegetables to purchase, the number of vegetables in the bag, and the price of each vegetable, and create a program that outputs the minimum purchase price.
Input
A sequence of multiple datasets is given as input. The end of the input is indicated by two lines of zeros. Each dataset is given in the following format:
n m
p1 p2 ... pn
The first line gives the number of vegetables to buy n (1 ≤ n ≤ 1000) and the number of vegetables to put in the bag m (1 ≤ m ≤ 1000). The second line gives the price pi (10 ≤ pi ≤ 10000) for each vegetable.
The number of datasets does not exceed 100.
Output
Prints the minimum purchase price on one line for each input dataset.
Example
Input
4 2
50 40 100 80
7 3
400 300 100 700 200 600 500
0 0
Output
150
2100 | 7 | 0 | #include<iostream>
#include<algorithm>
using namespace std;
int main()
{
int n, m, ans, p[1000];
while(1)
{
ans = 0;
cin >> n >> m;
if(m == n && !m)
break;
for(int i = 0; i < n; i++)
cin >> p[i];
sort(p, p + n);
reverse(p, p + n);
for(int i = 0; i < n; i++)
{
if((i + 1) % m)
ans += p[i];
}
cout << ans << endl;
}
return 0;
} | CPP |
p00227 Thanksgiving | As bad weather continues and vegetable prices soar, Seven-Eleven is offering customers bulk purchase sales of vegetables. The store is very busy, as you can get vegetables that are hard to find in stores at reasonable prices.
One day, a group of three good friends living in the Matsunaga housing complex bloomed with an advertisement for Seven-Eleven. Since this sale was called "Customer Thanksgiving Day", the highlight is that the cheapest vegetables in the bag are free. When I read the advertisement, it looks like the following sale.
* Up to m vegetables can be packed in one bag.
* For bags packed with m vegetables, the cheapest vegetables are free.
* Bags with less than m vegetables are not eligible for the discount.
The three went shopping at Seven Mart immediately.
When the three people who met outside the store after shopping were satisfied with the fact that they were able to buy a lot at a low price, they apparently found that they were all buying the same vegetables. One person said, "It's really cheap, isn't it? This is XXX yen!", And the other was surprised, "What? I was ** yen higher than that! Why?", And the rest One of them saw the receipt and noticed that he bought the cheapest one.
Now, how can you pack the bag at the lowest purchase price? Enter the number of vegetables to purchase, the number of vegetables in the bag, and the price of each vegetable, and create a program that outputs the minimum purchase price.
Input
A sequence of multiple datasets is given as input. The end of the input is indicated by two lines of zeros. Each dataset is given in the following format:
n m
p1 p2 ... pn
The first line gives the number of vegetables to buy n (1 ≤ n ≤ 1000) and the number of vegetables to put in the bag m (1 ≤ m ≤ 1000). The second line gives the price pi (10 ≤ pi ≤ 10000) for each vegetable.
The number of datasets does not exceed 100.
Output
Prints the minimum purchase price on one line for each input dataset.
Example
Input
4 2
50 40 100 80
7 3
400 300 100 700 200 600 500
0 0
Output
150
2100 | 7 | 0 | #include<iostream>
#include<string>
#include<vector>
#include<algorithm>
using namespace std;
int main(){
int n,m,data[1001];
while(cin>>n>>m&&n|m){
int sum=0;
for(int i=0;i<n;i++){
cin>>data[i];
sum+=data[i];
}
sort(data,data+n,greater<int>());
for(int i=m-1;i<n;i+=m)sum-=data[i];
cout << sum << endl;
}
} | CPP |
Subsets and Splits
No saved queries yet
Save your SQL queries to embed, download, and access them later. Queries will appear here once saved.