prompt
string
response
string
Problem: 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 Solution (in CPP):
#include <iostream> #include <utility> #include <vector> #include <algorithm> using namespace std; int main(void){ int n, a,f; vector<pair<int, int> > v; cin >> n; for (int i=0; i<n; i++){ cin >> a >> f; v.push_back(make_pair(-f, a)); } sort(v.begin(), v.end()); cout << v[0].second << " " << -v[0].first << endl; return 0; }
Problem: 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 Solution (in CPP):
#include <bits/stdc++.h> using namespace std; using ll = long long; using pii = pair<int, int>; int main() { cin.tie(0); ios_base::sync_with_stdio(false); cout << fixed << setprecision(10); int n; while (cin >> n) { vector<int> d(n); for (int i = 0; i < n; i++) { int a, v; cin >> a >> v; d[a - 1] = v; } int id = 0; for (int i = 0; i < n; i++) { if (d[i] > d[id]) id = i; } cout << id + 1 << " " << d[id] << endl; } return 0; }
Problem: 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 Solution (in CPP):
#include <iostream> #include <algorithm> #include <vector> using namespace std; int main() { int n; cin >> n; vector<int> a[101]; int max=0; for(int i=0; i<n; i++) { int x,y; cin >> x >> y; a[y].push_back(x); if(max<y) max=y; } sort(a[max].begin(),a[max].end()); cout << a[max][0] << " " << max << endl; return 0; }
Problem: 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 Solution (in JAVA):
import java.util.*; public class Main { public static void main(String[] args) { Scanner in=new Scanner(System.in); while(in.hasNext()) { int n=in.nextInt(); int max=-1; int ind=-1; for(int i=0;i<n;i++) { int id=in.nextInt(); int cnt=in.nextInt(); if(cnt>=max) { if(cnt==max) { if(id<ind) { ind=id; max=cnt; } } else { ind=id; max=cnt; } } } System.out.println(ind+" "+max); } } static public void debug(Object... o) { System.err.println(Arrays.deepToString(o)); } }
Problem: 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 Solution (in CPP):
#include <iostream> #include <queue> #include <algorithm> using namespace std; typedef pair<int,int> P; int main(){ int n,a,v; priority_queue<P,vector<P> > que; cin>>n; while(n--){ cin>>a>>v; que.push(P(v,a)); } v=que.top().first; a=que.top().second; que.pop(); while(!que.empty() && que.top().first==v){ a=min(a,que.top().second); que.pop(); } cout<<a<<" "<<v<<endl; return 0; }
Problem: 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 Solution (in PYTHON3):
n = int(input()) data = [0] * n for _ in range(n): a, v = [int(el) for el in input().split()] data[a-1] += v result = max(data) print(data.index(result)+1, result)
Problem: 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 Solution (in JAVA):
import java.io.BufferedReader; import java.io.IOException; import java.io.InputStreamReader; import java.util.Scanner; public class Main { public static void main(String[] args) throws IOException { BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); String s = ""; int[] top = new int[] { 21, -1 }; int n = Integer.parseInt(br.readLine()); int i = 0; while ((s = br.readLine()) != null) { if (i == n) break; Scanner sc = new Scanner(s); int _angler = sc.nextInt(); int _catch = sc.nextInt(); if (_angler < 0 || _angler > 20) continue; if (_catch < 0 || _angler > 100) continue; if (top[1] < _catch || (top[1] == _catch && top[0] > _angler)) { top[0] = _angler; top[1] = _catch; } i++; } System.out.println(top[0] + " " + top[1]); } }
Problem: 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 Solution (in CPP):
#include<iostream> #include<math.h> #include<vector> #include<algorithm> #include<cstdio> using namespace std; int main(){ int n; int num=1,max=0; int tmpnum,tmp; cin>>n; while(n){ cin>>tmpnum>>tmp; if(max==tmp){ if(num>tmpnum){ num=tmpnum; --n; continue; } } if(max<tmp){ num=tmpnum; max=tmp; } --n; } cout<<num<<" "<<max<<endl; return 0; }
Problem: 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 Solution (in PYTHON):
x=[map(int,raw_input().split()) for i in range(input())] a,v=sorted(x,key=lambda x:(-x[1],x[0]))[0] print a,v
Problem: 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 Solution (in JAVA):
import java.io.*; import java.util.ArrayDeque; import java.util.ArrayList; import java.util.Arrays; import java.util.Collections; import java.util.Comparator; import java.util.Deque; import java.util.HashMap; import java.util.List; import java.util.NoSuchElementException; import java.util.Scanner; public class Main { static int[][] map = new int[101][101]; static int[][] dp = new int[101][101]; public static void main(String[] args) { FastScanner sc = new FastScanner(); Scanner stdIn = new Scanner(System.in); PrintWriter out = new PrintWriter(System.out); int n = sc.nextInt(); Data[] list = new Data[n]; for(int i = 0; i < n; i++) { list[i] = new Data(sc.nextInt(),sc.nextInt()); } Arrays.sort(list,new Comp()); out.println(list[0].id + " " + list[0].point); out.flush(); } static class Data { int id; int point; Data(int a, int b) { id = a; point = b; } } static class Comp implements Comparator<Data>{ @Override public int compare(Data o1, Data o2) { if(o1.point > o2.point) { return -1; } if(o1.point < o2.point) { return 1; } if(o1.id < o2.id) { return -1; } return 1; } } } //------------------------------// //-----------// class FastScanner { private final InputStream in = System.in; private final byte[] buffer = new byte[1024]; private int ptr = 0; private int buflen = 0; private boolean hasNextByte() { if (ptr < buflen) { return true; }else{ ptr = 0; try { buflen = in.read(buffer); } catch (IOException e) { e.printStackTrace(); } if (buflen <= 0) { return false; } } return true; } private int readByte() { if (hasNextByte()) return buffer[ptr++]; else return -1;} private static boolean isPrintableChar(int c) { return 33 <= c && c <= 126;} private void skipUnprintable() { while(hasNextByte() && !isPrintableChar(buffer[ptr])) ptr++;} public boolean hasNext() { skipUnprintable(); return hasNextByte();} public String next() { if (!hasNext()) throw new NoSuchElementException(); StringBuilder sb = new StringBuilder(); int b = readByte(); while(isPrintableChar(b)) { sb.appendCodePoint(b); b = readByte(); } return sb.toString(); } public long nextLong() { if (!hasNext()) throw new NoSuchElementException(); long n = 0; boolean minus = false; int b = readByte(); if (b == '-') { minus = true; b = readByte(); } if (b < '0' || '9' < b) { throw new NumberFormatException(); } while(true){ if ('0' <= b && b <= '9') { n *= 10; n += b - '0'; }else if(b == -1 || !isPrintableChar(b)){ return minus ? -n : n; }else{ throw new NumberFormatException(); } b = readByte(); } } public int nextInt() { return (int)nextLong(); } }
Problem: 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 Solution (in PYTHON3):
n=int(input()) l=[] for i in range(n): x,y=map(int,input().split()) l.append((y,x)) l.sort(key=lambda x:(x[0],x[1]),reverse=True) maximum=l[0][0] young=l[0][1] for i in l: if maximum==i[0]: young=i[1] else: break print(young,maximum)
Problem: 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 Solution (in CPP):
#include<stdio.h> int main(){ int n,i,a[20]={},v[20]={}; int tmp; scanf("%d",&n); for(i=0;i<n;i++){ scanf("%d%d",&a[i],&v[i]); } int j,h; for(j=0;j<n-1;j++){ for(h=n-1;h>j;h--){ if(v[h]>v[h-1]){ tmp=v[h]; v[h]=v[h-1]; v[h-1]=tmp; tmp=a[h]; a[h]=a[h-1]; a[h-1]=tmp; } } } int max=v[0]; for(i=1;i<n;i++){ if(max==v[i]){ if(a[0]>a[i]){ tmp=a[0]; a[0]=a[i]; a[i]=tmp; } } } printf("%d %d\n",a[0],v[0]); return 0; }
Problem: 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 Solution (in PYTHON3):
n = int(input()) result = [] for i in range(n): result.append(list(map(int, input().split()))) result.sort(key=lambda x: (-x[1], x[0])) print(*result[0])
Problem: 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 Solution (in CPP):
#include <bits/stdc++.h> using namespace std; int main(){ int al=99999,vl=0,n; cin>>n; int a,v; for(int i=0;i<n;i++){ cin>>a>>v; if(v>vl){ vl=v; al=a; }else if(v==vl){ if(al>a)al=a; } } cout<<al<<" "<<vl<<endl; }
Problem: 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 Solution (in JAVA):
public class Main{ public void run(java.io.InputStream in, java.io.PrintStream out){ java.util.Scanner sc = new java.util.Scanner(in); /*answer*/ int n, i, v, max, m, mmin; n = sc.nextInt(); max = -1; mmin = -1; for(i = 0;i < n;i++){ m = sc.nextInt(); v = sc.nextInt(); if(max < v || (max == v && mmin > m)){ max = v; mmin = m; } } out.println(mmin + " " + max); sc.close(); } public static void main(String[] args){ (new Main()).run(System.in, System.out); } }
Problem: 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 Solution (in CPP):
#include <cstdio> #include <queue> typedef std::pair<int, int> P; int n; int main(){ scanf("%d", &n); std::priority_queue<P> que; for(int i = 0; i < n; i++){ int a, b; scanf("%d %d", &a, &b); que.push(P(b, a)); } P p = que.top(); que.pop(); while(!que.empty()){ P q = que.top(); que.pop(); if(q.first < p.first) break; if(p.second > q.second){ p = q; } } printf("%d %d\n", p.second, p.first); return 0; }
Problem: 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 Solution (in CPP):
#include<iostream> using namespace std; int main() { int n; cin>>n; int a=1000,v=0; for(int i = 0; i < n; ++i) { int aa,vv; cin>>aa>>vv; if(v<vv) { a=aa; v=vv; } else { if(v==vv&&aa<a) { a=aa; } } } cout<<a<<" "<<v<<endl; return 0; }
Problem: 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 Solution (in CPP):
#include<cstdio> int n; int a[21],v[21]; int main(void){ scanf("%d",&n); for(int i=0;i<n;i++)scanf("%d%d",&a[i],&v[i]); int mid=a[0],m=v[0]; for(int i=1;i<n;i++){ if(m<v[i]){ mid=a[i]; m=v[i]; } if(m==v[i] && mid>a[i])mid=a[i]; } printf("%d %d\n",mid,m); return 0; }
Problem: 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 Solution (in CPP):
#include <stdio.h> int main(void) { int i; int n; int a; int v; int ma; int mv; scanf("%d", &n); mv = 0; for (i = 0; i < n; i++){ scanf("%d %d", &a, &v); if (v > mv || v >= mv && a < ma){ mv = v; ma = a; } } printf("%d %d\n", ma, mv); return (0); }
Problem: 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 Solution (in CPP):
#include <cstdio> #include <utility> #include <algorithm> using namespace std; typedef pair<int, int> Pair; int n; int a, v; Pair ans(-1, -1); int main() { scanf("%d", &n); for (int i=0; i<n; i++) { scanf("%d%d", &a, &v); ans = max(ans, Pair(v, -a)); } printf("%2$d %1$d\n", ans.first, -ans.second); }
Problem: 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 Solution (in CPP):
#include<iostream> using namespace std; int main(){ int n,a[20],v[20],b=0; cin >>n; for(int i=0 ; i < n ; i++){ cin >>a[i]>>v[i]; } for(int i=0 ; i < n ; i++){ if(v[b] < v[i]){ b=i; }else if(v[b] == v[i] && a[b] > a[i]){ b=i; } } cout <<a[b]<<" "<<v[b]<<endl; return 0; }
Problem: 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 Solution (in CPP):
#include <iostream> #include <map> #include <vector> #include <algorithm> #include <functional> using namespace std; int main () { int n; cin >> n; vector <pair<int,int> > V; for (int i = 0; i <= n; i++) { V.push_back(pair<int,int>(0,i)); } for (int i = 0; i < n; i++) { int a, b; cin >> a >> b; V[a].first += b; } sort(V.begin(), V.end()); int i = 1; while (V[i].first != V[n].first) i++; cout << V[i].second << " " << V[i].first << endl; return 0; }
Problem: 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 Solution (in PYTHON):
n = int(raw_input()) mxs, minm = 0, 21 for i in range(n): m, s = map(int, raw_input().split()) if s > mxs: mxs = s minm = m elif s == mxs: if m < minm: minm = m print minm, mxs
Problem: 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 Solution (in CPP):
#include<iostream> using namespace std; int main() { int n; int g[20] = {}, p[20] = {}; cin >> n; for( int i = 0; i < n; i++ ) cin >> g[i] >> p[i]; int max = -1; for( int i = 0; i < n; i++ ) { if( max < p[i] ) max = p[i]; } int min = 1000; for( int i = 0; i < n; i++ ) { if( p[i] == max ) { if( min > g[i] ) min = g[i]; } } cout << min << " " << max << endl; return 0; }
Problem: 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 Solution (in JAVA):
import java.util.Scanner; public class Main { private Scanner sc; public static void main(String[] args) { new Main(); } public Main() { sc = new Scanner(System.in); int num = 21; int max = -1; int nico = Integer.parseInt(sc.nextLine()); for (int i = 0; i < nico; i++) { String[] data = sc.nextLine().split(" "); int tmpn = Integer.parseInt(data[0]); int tmpm = Integer.parseInt(data[1]); if (max <= tmpm) { if (max == tmpm) { if (num > tmpn) num = tmpn; } else { max = tmpm; num = tmpn; } } } System.out.println(num + " " + max); } }
Problem: 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 Solution (in CPP):
#include <iostream> #include <utility> #include <algorithm> #include <vector> using namespace std; typedef pair<int, int> P; int main(){ int n; cin >> n; int m_a , m_v = 0, a, v; for(int i = 0; i < n; i++){ cin >> a >> v; if( v > m_v || (v == m_v && a < m_a )){ m_v = v; m_a = a; } } cout << m_a << ' ' << m_v << endl; return 0; }
Problem: 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 Solution (in CPP):
#include <iostream> using namespace std; int main() { int n, a, v, a_res=21, v_res=0; while(cin>>n) { while(n--) { cin >> a >> v; if ((v_res == v && a_res > a) || (v_res < v)) { a_res = a; v_res = v; } } cout << a_res << " " << v_res << endl; } return 0; }
Problem: 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 Solution (in CPP):
#include<iostream> #include<string.h> #include<cstdio> #include<algorithm> #include<stack> #include<queue> #include<vector> #include<cmath> #include<utility> #define ll long long int #define ld long double #define INF 1000000000 #define EPS 0.0000000001 #define rep(i,n) for(i=0;i<n;i++) using namespace std; typedef pair<int, int> P; string str; int main() { int n; pair<int,int> num[105]; int i; cin>>n; rep(i,n){ cin>>num[i].second>>num[i].first; num[i].first*=-1; } sort(num,num+n); cout<<num[0].second<<" "<<-num[0].first<<endl; }
Problem: 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 Solution (in CPP):
#include<stdio.h> int main() { int n; int a,v[20],r[20],max=0; scanf("%d",&n); for(int i=0;i<n;i++){ scanf("%d %d",&a,&v[i]); r[a-1]=v[i]; } for(int i=0;i<n;i++){ if(r[i]>max){ max=r[i]; } } for(int i=0;i<n;i++){ if(max==r[i]){ printf("%d %d\n",i+1,r[i]); break; } } return 0; }
Problem: 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 Solution (in JAVA):
import java.util.Scanner; public class Main{ public static void main(String[] args){ Scanner scan = new Scanner(System.in); while(scan.hasNext()){ int n = scan.nextInt(); int p = scan.nextInt(); int f = scan.nextInt(); for(int i = 1;i < n;i++){ int a = scan.nextInt(); int b = scan.nextInt(); if(f < b){ p = a; f = b; }else if(f == b){ p = (p < a)?p:a; } } System.out.println(p + " " + f); } } }
Problem: 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 Solution (in CPP):
#include<iostream> using namespace std; int main(){ int n,a,v,max=0,maxn=999; cin >>n; for(int i=0;i<n;++i){ cin >>a >>v; if(v>max){ max=v; maxn=a; } else if(v==max) if(a<maxn) maxn=a; } cout <<maxn <<" " <<max <<'\n'; return 0; }
Problem: 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 Solution (in JAVA):
import java.util.Scanner; public class Main { public static void main(String[] args) { Scanner scan = new Scanner(System.in); int input = scan.nextInt(); int n = 0; if(input >= 1 && input <= 20)n = input; int a = Integer.MAX_VALUE; int v = Integer.MIN_VALUE; for(int i = 0 ; i < n ; i++) { int num = scan.nextInt(); int fishNum = scan.nextInt(); if(fishNum > v) { v = fishNum; a = num; }else if(fishNum == v) { a = Integer.min(a, num); } } System.out.println(a + " " + v); scan.close(); } }
Problem: 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 Solution (in PYTHON):
n = input() pat = [0] * n for i in range(n): a, v = map(int, raw_input().split()) pat[a-1] = v m = max(pat) print pat.index(m)+1, m
Problem: 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 Solution (in CPP):
#include <iostream> #include <cmath> using namespace std; int main() { int n; int max[2]; int a, b; cin >> n; cin >> max[0] >> max[1]; for (int i = 1; i < n; i++) { cin >> a >> b; if (b > max[1]) { max[1] = b; max[0] = a; } else if (b == max[1]) { max[0] = min(max[0], a); } } cout << max[0] << " " << max[1] << endl; return 0; }
Problem: 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 Solution (in CPP):
#include<stdio.h> int fish[21]={0}; int n; int a,b; int memo[2]={0}; int date=100; int main() { scanf("%d",&n); for(int i=0;i<n;i++) { scanf("%d%d",&a,&b); if(a<date)date=a; memo[0]=date; fish[a] +=b; } for(int i=0;i<21;i++) { if(fish[i]>memo[1]) { memo[0]=i; memo[1]=fish[i]; } } printf("%d %d\n",memo[0],memo[1]); return 0; }
Problem: 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 Solution (in CPP):
#include<stdio.h> int main(void) { int n,a,b,c,i,max,min; max=-1; min=101; scanf("%d",&n); for(i=0;i<n;i++){ scanf("%d %d",&a,&b); if(max==b&&min>a){ min=a; } if(max<b){ max=b; min=a; } } printf("%d %d\n",min,max); return 0; }
Problem: 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 Solution (in PYTHON3):
# Aizu Problem 0095: Surf Smelt Fishing Contest # import sys, math, os # read input: PYDEV = os.environ.get('PYDEV') if PYDEV=="True": sys.stdin = open("sample-input.txt", "rt") N = int(input()) A = sorted([[int(_) for _ in input().split()] for __ in range(N)], key=lambda x: (-x[1], x[0])) print(A[0][0], A[0][1])
Problem: 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 Solution (in CPP):
#include <iostream> using namespace std; int main() { int n, a, v, maxa, maxv; cin >> n >> maxa >> maxv; for (int i=0; i<n-1; i++) { cin >> a >> v; if(v == maxv){ if(a < maxa){ maxa = a; maxv = v; } } else if(v > maxv){ maxa = a; maxv = v; } } cout << maxa << ' ' << maxv << endl; return 0; }
Problem: 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 Solution (in CPP):
#include <iostream> using namespace std; int main(){ long long int n,a,b,max = -1,ans; cin >> n; while(n--){ cin >> a >> b; if(max < b ){ max = b; ans = a; }else if(max == b && ans > a ){ ans = a; } } cout << ans << " " << max << endl; }
Problem: 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 Solution (in CPP):
#include <cstdio> #include <utility> #include <algorithm> #include <vector> using namespace std; int main(){ int n, a, b; scanf("%d", &n); vector<pair<int,int> > v(n); for(int i = 0; i < n; ++i){ scanf("%d%d", &a, &b); v[i].first = b; v[i].second = -a; } const pair<int,int> &p = *max_element(v.begin(), v.end()); printf("%d %d\n", -p.second, p.first); }
Problem: 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 Solution (in CPP):
#include <iostream> using namespace std; int main(){ for(int n,a,v=-1;cin>>n;cout<<a<<' '<<v<<endl) for(int i=0;i<n;i++){ int x,y; cin>>x>>y; if(v<y||v==y&&a>x) a=x,v=y; } return 0; }
Problem: 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 Solution (in JAVA):
import java.util.Scanner; public class Main { public static void main(String[] args) { Scanner sc = new Scanner(System.in); int n = sc.nextInt(); int ra = 101, rb = -1; while(n--!=0){ int a = sc.nextInt(), b = sc.nextInt(); if(rb < b || rb==b && a < ra){ ra = a; rb = b; } } System.out.println(ra+" "+rb); } }
Problem: 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 Solution (in CPP):
//Surf Smelt Fishing Contest #include<bits/stdc++.h> using namespace std; vector<pair<int, int> > v; bool comp(const pair<int, int> &a, const pair<int, int> &b){ if(a.second==b.second)return a.first<b.first; return a.second>b.second; } int main(){ int n; cin>>n; for(int i=0; i<n; i++){ int a, b; cin>>a>>b; v.push_back(make_pair(a, b)); } sort(v.begin(), v.end(), comp); cout<<v[0].first<<' '<<v[0].second<<endl; return 0; }
Problem: 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 Solution (in CPP):
#include <iostream> using namespace std; int main() { int n, index, w, idx = 0, mx = -1; cin >> n; for(int i=0;i < n; ++i) { cin >> index >> w; if (mx < w || (mx == w && idx > index)) idx = index, mx = w; } cout << idx << " " << mx << endl; return 0; }
Problem: 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 Solution (in CPP):
#include <cstdio> #include <vector> #include <algorithm> using namespace std; int main(){ int n,a,b; vector<pair<int,int> >v; for(scanf("%d",&n);n--;v.push_back(make_pair(-b,a)))scanf("%d%d",&a,&b); sort(v.begin(),v.end()); printf("%d %d\n",v[0].second,-v[0].first); }
Problem: 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 Solution (in CPP):
#include<iostream> #include<algorithm> #include<functional> using namespace std; int main(){ int n; int person[22], fish[22]; int array[22]; int fisherMan[22]; int fisher = 0; cin >> n; for(int i=0; i < n; i++){ cin >> person[i] >> fish[i]; array[i] = fish[i]; } sort(array, array+n, greater<int>()); for(int i=0; i < n; i++){ if(fish[i] == array[0]){ fisherMan[fisher] = person[i]; fisher++; } } sort(fisherMan, fisherMan+fisher); cout << fisherMan[0] << " " << array[0] << endl; }
Problem: 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 Solution (in JAVA):
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,v; int maxPtr=0; int max=-1; for(int i=0;i<n;i++){ a=sc.nextInt(); v=sc.nextInt(); if(v>max||max==v&&a<maxPtr){ max=v; maxPtr=a; } } System.out.println(maxPtr+" "+max); } }
Problem: 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 Solution (in CPP):
#include <cstdio> using namespace std; int main() { int n, a, b, max_a, max_b; scanf("%d", &n); max_a = max_b = -1; for (int i=0; i<n; i++) { scanf("%d %d", &a, &b); if (max_b<b) { max_b = b; max_a = a; } else if (max_b==b && max_a>a) { max_a = a; } } printf("%d %d\n", max_a, max_b); return 0; }
Problem: 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 Solution (in PYTHON3):
num = 1000 val = 0 n = int(input()) for i in range(n): a, b = map(int, input().split()) if b > val or (b == val and a < num): val = b num = a print(num, val)
Problem: 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 Solution (in CPP):
#include<iostream> #include<string> using namespace std; int main(){ int n,a[21],b,c,d=0; cin>>n; for(int i=0;i<n;i++){ cin>>b>>c; a[b]=c; if(d<c) d=c; } int i=1; while(true){ if(a[i]==d){ cout<<i<<" "<<a[i]<<endl; break; } i++; } return 0; }
Problem: 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 Solution (in CPP):
#include<algorithm> #include<iostream> #include<vector> #include<utility> typedef std::pair<int,int> P; bool compare( const P& lhs, const P& rhs ) { if( lhs.first != rhs.first ) return lhs.first > rhs.first; return lhs.second < rhs.second; } int main() { int n; std::cin >> n; std::vector<P> vec; while( n-- ) { int a, v; std::cin >> a >> v; vec.push_back( std::make_pair( v, a ) ); } std::sort( vec.begin(), vec.end(), compare ); std::cout << vec[0].second << " " << vec[0].first << std::endl; return 0; }
Problem: 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 Solution (in PYTHON):
print " ".join(map(str,sorted([map(int,raw_input().split()) for u in xrange(input())],cmp=lambda a,b:cmp(a[0],b[0]) if a[1] == b[1] else cmp(b[1],a[1]))[0]))
Problem: 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 Solution (in JAVA):
import java.util.Scanner; /** * AOJのVolume0の0095を解くクラス * @author たっちゃん * */ public class Main { /** * mainメソッド。 * @param args 使用せず */ public static void main(String[] args) { Scanner scan = new Scanner(System.in); int n = scan.nextInt(); int minA = Integer.MAX_VALUE, maxV = Integer.MIN_VALUE; for(int i = 0; i < n; i++) { int a = scan.nextInt(); int v = scan.nextInt(); if(maxV < v) { minA = a; maxV = v; } else if(maxV == v) { minA = Integer.min(minA, a); } } System.out.println(minA + " " + maxV); scan.close(); } }
Problem: 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 Solution (in CPP):
//24 #include<iostream> using namespace std; int main(){ int n; cin>>n; int x,m=-1; while(n--){ int a,v; cin>>a>>v; if(v>m||v==m&&a<x){ m=v; x=a; } } cout<<x<<' '<<m<<endl; return 0; }
Problem: 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 Solution (in JAVA):
import java.util.*; import java.io.*; public class Main { public void solve() throws IOException { int n = nextInt(); int[] v = new int[n+1]; for(int i = 0; i < n; i++){ int a = nextInt(); int x = nextInt(); v[a] += x; } int ans = 1; for(int i = 1; i <= n; i++){ if( v[i] > v[ans] ){ ans = i; } } writer.println(ans + " " + v[ans]); } public static void main(String[] args) throws IOException { new Main().run(); } BufferedReader reader; StringTokenizer tokenizer; PrintWriter writer; public void run() throws IOException { try { reader = new BufferedReader(new InputStreamReader(System.in)); tokenizer = null; writer = new PrintWriter(System.out); solve(); reader.close(); writer.close(); } catch (Exception e) { e.printStackTrace(); } } public String nextToken() throws IOException { while (tokenizer == null || !tokenizer.hasMoreTokens()) { tokenizer = new StringTokenizer(reader.readLine()); } return tokenizer.nextToken(); } public int nextInt() throws IOException { return Integer.parseInt(nextToken()); } }
Problem: 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 Solution (in JAVA):
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,v; int maxPtr=0; int max=-1; 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); } }
Problem: 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 Solution (in CPP):
#include<iostream> using namespace std; int main(){ long n,i,a,b,aa,bb=0; cin>>n; for(i=0;i<n;i++){ cin>>a>>b; if(bb<b){aa=a;bb=b;} else if(bb==b&&a<aa){aa=a;bb=b;} } cout<<aa<<" "<<bb<<endl; return 0; }
Problem: 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 Solution (in CPP):
#include <iostream> #include <map> #include <algorithm> using namespace std; #define loop(i,a,b) for(int i=(a); i<(int)(b); i++) #define rep(i,b) loop(i,0,b) typedef pair<int,int> P; int main(){ int n;cin>>n; P arr[20]; rep(i,n){ int a,v;cin>>a>>v; arr[i]=make_pair(a,v); } partial_sort(arr,arr+1,arr+n, [](const P& a, const P& b){ if(a.second!=b.second) return a.second>b.second; return a.first<b.first; }); cout<<arr[0].first<<" "<<arr[0].second<<endl; }
Problem: 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 Solution (in PYTHON3):
a={} for i in range(int(input())): b,c=map(int,input().split()) a[b]=c d=max(a.items(),key=lambda x:x[1]) print(*d)
Problem: 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 Solution (in CPP):
#include <iostream> int main(void){ int n,a,b,max=0,c=21; std::cin>>n; for(int i=0;i<n;i++){ std::cin>>a>>b; if(max<=b){ if(max==b){ if(c>a)c=a; continue; } max=b; c=a; } } std::cout<<c<<" "<<max<<'\n'; return 0; }
Problem: 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 Solution (in CPP):
#include <bits/stdc++.h> using namespace std; int main() { int n, num, w; pair<int, int> p[20]; cin >> n; for (int i = 0; i < n; i++) { cin >> num >> w; p[i] = make_pair(-w, num); } sort(p, p+n); cout << p[0].second << ' ' << (-1) * p[0].first << endl; return 0; }
Problem: 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 Solution (in CPP):
#include <cstdio> #include <algorithm> #include <map> using namespace std; int main(void){ int n; scanf("%d",&n); pair<int,int> best = make_pair(0,-100); for(int i = 0; i < n; i++){ pair<int,int> p; scanf("%d %d",&p.second,&p.first); p.second *= -1; if(p > best) best = p; } printf("%d %d\n",-best.second,best.first); }
Problem: 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 Solution (in PYTHON3):
# -*- coding: utf-8 -*- import sys import os import math N = int(input()) A = [None] * N for i in range(N): id, num = map(int, input().split()) id -= 1 A[id] = num max_value = max(A) max_index = A.index(max_value) print(max_index + 1, max_value)
Problem: 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 Solution (in CPP):
#include <iostream> using namespace std; int main() { int n, nf, num, mnf, mnum; cin >> n; cin >> mnum >> mnf; n--; while (n--) { cin >> num >> nf; if (nf > mnf) { mnf = nf; mnum = num; } if (nf == mnf && num < mnum) mnum = num; } cout << mnum << " " << mnf << endl; return 0; }
Problem: 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 Solution (in CPP):
#include <iostream> #include <algorithm> using namespace std; int main() { int n; int max_ = -1, id; int a, v; cin >> n; for(int i = 0; i < n; ++i) { cin >> a >> v; if(max_ < v){ max_ = v; id = a; } else if(max_ == v && id > a){ id = a; } } cout << id << ' ' << max_ << endl; }
Problem: 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 Solution (in JAVA):
import java.util.Scanner; public class Main { void run(){ Scanner sc = new Scanner(System.in); int n = sc.nextInt(); int ra = 101, rb = -1; while(n--!=0){ int a = sc.nextInt(), b = sc.nextInt(); if(rb < b || rb==b && a < ra){ ra = a; rb = b; } } System.out.println(ra+" "+rb); } public static void main(String[] args) { new Main().run(); } }
Problem: 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 Solution (in CPP):
#include<iostream> using namespace std; int main(){ int A,B=-1; int n; cin >> n; while(n--){ int a,b; cin >> a >> b; if(B < b || B == b && A > a){ A = a; B = b; } } cout << A << " " << B << endl; return 0; }
Problem: 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 Solution (in PYTHON3):
n=int(input()) d={} for _ in range(n): a,v=list(map(int,input().split())) if not v in d: d[v]=[a] else: d[v].append(a) m=max(d.keys()) print(sorted(d[m])[0],m)
Problem: 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 Solution (in CPP):
#include <bits/stdc++.h> #define rep(i,l,n) for(int i=l;i<n;i++) #define rer(i,l,n) for(int i=l;i<=n;i++) #define all(a) a.begin(),a.end() #define o(a) cout<<a<<endl #define fi first #define se second using namespace std; typedef long long ll; typedef vector<int> vint; typedef pair<int,int> pii; int main(){ int n,a,v; pii d[25]={}; cin>>n; rer(i,1,n) d[i].se=i; rep(i,0,n){ cin>>a>>v; d[a].fi=v; } sort(d+1,d+n+1); rer(i,1,n){ if(d[i].fi==d[n].fi){ o(d[i].se<<" "<<d[i].fi); break; } } }
Problem: 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 Solution (in JAVA):
import java.util.ArrayList; import java.util.Scanner; class Score { private int id; private int pt; Score(int id, int pt){ this.id = id; this.pt = pt; } public int getId() { return id; } public void setId(int id) { this.id = id; } public int getPt() { return pt; } public void setPt(int pt) { this.pt = pt; } } public class Main { public static void main(String[] args) { ArrayList<Score> s = new ArrayList<Score>(); Scanner sc = new Scanner(System.in); int n = sc.nextInt(); for (int i = 0; i < n; i++) { s.add( new Score(sc.nextInt(), sc.nextInt()) ); } s.sort((a,b)-> a.getId() - b.getId() ); s.sort((a,b)-> b.getPt() - a.getPt() ); System.out.printf("%d %d\n", s.get(0).getId(), s.get(0).getPt()); sc.close(); } }
Problem: 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 Solution (in CPP):
#include <iostream> using namespace std; int main(){ int n; int fish[20]={0}; cin>>n; for(int i=0;i<n;i++){ int a,v; cin>>a>>v; fish[a-1]=v; } int max=fish[0],b=0; for(int j=1;j<20;j++){ if(max<fish[j]){ max=fish[j]; b=j; } } cout<<b+1<<" "<<max<<endl; return 0; }
Problem: 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 Solution (in PYTHON):
n=input() x=[map(int,raw_input().split()) for i in range(n)] a,v=sorted(x,key=lambda x:(-x[1],x[0]))[0] print a,v
Problem: 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 Solution (in PYTHON):
#!/usr/bin/env python from __future__ import division, print_function from sys import stdin, exit, maxsize def main(readline=stdin.readline): value = -1 number = maxsize for _ in range(int(readline())): a, v = (int(s) for s in readline().split()) if v > value or v == value and a < number: number = a value = v print(number, value) exit() main()
Problem: 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 Solution (in CPP):
#include<iostream> #include<algorithm> using namespace std; int main() { int n; cin >> n; int maxn, maxs; cin >> maxn >> maxs; for (int i = 0; i < n - 1; i++){ int a, b; cin >> a >> b; if (maxs < b){ maxn = a; maxs = b; } else if (maxs == b){ maxn = min(maxn, a); } } cout << maxn <<' '<< maxs << endl; }
Problem: 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 Solution (in JAVA):
/** * */ import java.util.*; /** * @author akira * */ class Main { /** * @param args */ public static void main(String[] args) { // TODO 自動生成されたメソッド・スタブ Scanner scan = new Scanner(System.in); int n; n = scan.nextInt(); ArrayList<fisher> alf = new ArrayList<fisher>(); for(int i = 0;i < n;i++){ alf.add(new fisher(scan.nextInt(),scan.nextInt())); } Collections.sort(alf,new Compare()); System.out.println(alf.get(0).a + " " + alf.get(0).v); } } class fisher{ int a; int v; fisher(int arg1,int arg2){ a = arg1; v = arg2; } } class Compare implements Comparator<fisher>{ public int compare(fisher f1,fisher f2){ if(f1.v < f2.v){ return 1; }else if(f1.v > f2.v){ return -1; }else{ if(f1.a < f2.a){ return -1; }else{ return 1; } } } }
Problem: 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 Solution (in CPP):
#include <iostream> using namespace std; int main() { int n; cin >> n; int maxv = -1, maxa = -1; for (int i = 0; i < n; i++) { int a, v; cin >> a >> v; if (v > maxv) { maxv = v; maxa = a; } else if (v == maxv && a < maxa) { maxa = a; } } cout << maxa << " " << maxv << endl; }
Problem: 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 Solution (in JAVA):
import java.io.BufferedReader; import java.io.IOException; import java.io.InputStreamReader; import java.util.Scanner; public class Main { public static void main(String[] args) throws IOException { BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); String s = ""; int[] top = new int[] { 21, -1 }; br.readLine(); // int n = Integer.parseInt(br.readLine()); // int i = 0; while ((s = br.readLine()) != null) { // if (i == n) // break; Scanner sc = new Scanner(s); int _angler = sc.nextInt(); int _catch = sc.nextInt(); // if (_angler < 0 || _angler > 20) // continue; // if (_catch < 0 || _angler > 100) // continue; if (top[1] < _catch || (top[1] == _catch && top[0] > _angler)) { top[0] = _angler; top[1] = _catch; } // i++; } System.out.println(top[0] + " " + top[1]); } }
Problem: 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 Solution (in PYTHON3):
# AOJ 0095 Surf Smelt Fishing Contest # Python3 2018.6.21 bal4u n = int(input()) tbl = [0]*(n+1) vmax = 0 for i in range(n): a, v = list(map(int, input().split())) tbl[a] += v if tbl[a] > vmax: vmax = tbl[a] for i in range(1, n+1): if tbl[i] == vmax: print(i, vmax) break
Problem: 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 Solution (in PYTHON3):
N = int(input()) maxA = -1 maxV = -1 for l in range(N): a,v = [int(i) for i in input().split()] if v > maxV: maxV = v maxA = a elif v == maxV: maxA = min(a, maxA) print(maxA, maxV)
Problem: 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 Solution (in CPP):
#include <algorithm> #include <vector> #include <map> #include <iostream> using namespace std; int main() { int n, max = 0; cin >> n; vector<pair<int, int> > pairs(n); for (int i = 0; i < n; i++) { int a, v; cin >> a >> v; pairs[i] = make_pair(a, v); } sort(pairs.begin(), pairs.end()); for (int i = 0; i < n; i++) { max = pairs[i].second > pairs[max].second? i: max; } cout << pairs[max].first << ' ' << pairs[max].second << endl; return 0; }
Problem: 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 Solution (in CPP):
#include<iostream> #include<cstdio> #include<algorithm> #include<climits> #include<string> using namespace std; struct Data{ int A,B; bool operator<(const Data &a)const{ if(B!=a.B) return B>a.B; else return A<a.A; } }; int main(){ int N; Data H[20]; cin>>N; for(int i=0;i<N;i++){ cin>>H[i].A>>H[i].B; } sort(H,H+N); printf("%d %d\n",H[0].A,H[0].B); return 0; }
Problem: 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 Solution (in CPP):
#include<iostream> using namespace std; int main(){ int n; //参加者数 cin >> n; int* a; //参加者番号 int* v; //匹数 a = new int[n]; v = new int[n]; for (int i = 0; i < n; i++){ cin >> a[i] >> v[i]; } int winner = a[0]; int max = v[0]; for (int i = 1; i < n; i++){ if (v[i]>max){ winner = a[i]; max = v[i]; } else if (v[i] == max && a[i] < winner){ winner = a[i]; } } cout << winner << " " << max << endl; return 0; }
Problem: 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 Solution (in PYTHON3):
num = int(input()) L = [] for i in range(num): p, v = [int(x) for x in input().split()] L.append([p, v]) L.sort(key=lambda x: (-x[1],x[0])) print(L[0][0],L[0][1])
Problem: 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 Solution (in CPP):
#include <iostream> #include <utility> #include <algorithm> #include <vector> using namespace std; bool compare(pair<int,int> a, pair<int,int> b) { if(a.second == b.second ) return a.first < b.first; else return a.second > b.second; } int main() { vector<pair<int,int> > in; int n; cin >> n; for(int i = 0; i < n; i++) { pair<int,int> tmp; cin >> tmp.first >> tmp.second; in.push_back(tmp); } sort(in.begin(), in.end(), compare); cout << in[0].first << " " << in[0].second << endl; return 0; }
Problem: 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 Solution (in CPP):
#include <iostream> using namespace std; int main(){ int a,b,n; int x[2]={21,0}; cin>>n; while(n--){ cin>>a>>b; if(x[1]<=b){ x[0]=(x[1]==b)?(x[0]>a)?a:x[0]:a;x[1]=b; } } cout<<x[0]<<' '<<x[1]<<endl; return 0; }
Problem: 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 Solution (in PYTHON3):
n = int(input()) fish = [] for i in range(n) : a, v = map(int, input().split()) fish.append([a, v]) fish.sort(key = lambda val: val[0]) fish.sort(reverse = True, key = lambda val: val[1]) print(*fish[0])
Problem: 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 Solution (in CPP):
#include "bits/stdc++.h" using namespace std; int a,b,c; int n; int main(){ cin>>n; pair<int,int> p[n]; for (int i = 0; i < n; ++i) { cin>>a>>b; p[i].second=a;p[i].first=-b; } sort(p,p+n); cout<<p[0].second<<" "<<-p[0].first<<endl; //cout<<p[n-1].second<<" "<<-p[n-1].first<<endl; }
Problem: 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 Solution (in CPP):
#include <iostream> using namespace std; int main() { int n; int w1, max = 0; cin >> n; for (int i = 0; i < n; i++){ int a, v; cin >> a >> v; if (max < v){ max = v; w1 = a; } else if (max == v){ if (w1 > a){ w1 = a; } } } cout << w1 << ' ' << max << endl; return (0); }
Problem: 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 Solution (in CPP):
#include<iostream> #include<map> #include<algorithm> using namespace std; typedef pair < int , int > Pi; int main(){ int n; Pi a[20]; cin >> n; for(int i = 0 ; i < n ; i++ ){ cin >> a[i].second >> a[i].first; a[i].second = -a[i].second; } sort( a, a + n); Pi *itr = max_element(a, a + n); cout << -(*itr).second << " " << (*itr).first << endl; }
Problem: 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 Solution (in PYTHON):
n=input() x=[0]*n for i in range(n): a,v=map(int,raw_input().split()) x[a-1]=v m=max(x) print x.index(m)+1,m
Problem: 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 Solution (in CPP):
#include <iostream> #include <algorithm> #include <vector> using namespace std; int main(){ int n,p,w; cin >> n; int max = 0; int maxp = 100; for(int i=0;i<n;i++){ cin >> p; cin >> w; if(max < w){ maxp = p; max = w; }else if(max == w){ if(maxp > p){ maxp = p; } } } cout << maxp << " " << max << endl; return 0; }
Problem: 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 Solution (in JAVA):
import java.io.BufferedReader; import java.io.IOException; import java.io.InputStreamReader; public class Main { public static void main(String[] args) throws NumberFormatException, IOException { BufferedReader input = new BufferedReader(new InputStreamReader(System.in)); final int dataCount = Integer.valueOf(input.readLine()); int[][] array = new int[dataCount][2]; for (int i = 0; i < dataCount; i++) { String[] INPUT_STR = input.readLine().split(" "); array[i][0] = Integer.valueOf(INPUT_STR[0]); array[i][1] = Integer.valueOf(INPUT_STR[1]); } int max = -1; int index = -1; for (int i = 0; i < array.length; i++) { if (max < array[i][1]) { max = array[i][1]; index = array[i][0]; } else if (max == array[i][1] && index > array[i][0]) { index = array[i][0]; } } System.out.println(index + " " + max); } }
Problem: 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 Solution (in CPP):
#include <iostream> using namespace std; int main() { int n; cin >> n; int amin = 0; int vmax = -1; for (int i = 0; i < n; ++i) { int a, v; cin >> a >> v; if (v < vmax || (v == vmax && amin < a)) continue; amin = a; vmax = v; } cout << amin << " " << vmax << endl; }
Problem: 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 Solution (in JAVA):
import java.io.IOException; import java.io.BufferedReader; import java.io.InputStreamReader; class Main { public static void main(String[] args) throws IOException { BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); int n = Integer.parseInt(br.readLine()); int[] score = new int[n + 1]; for (int i = 0; i < n; i++) { String[] input = br.readLine().split(" "); score[Integer.parseInt(input[0])] = Integer.parseInt(input[1]); } int maxValue = Integer.MIN_VALUE; int maxIndex = -1; for (int i = 1; i <= n; i++) { if (maxValue < score[i]) { maxValue = score[i]; maxIndex = i; } } System.out.println(maxIndex + " " + maxValue); } }
Problem: 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 Solution (in CPP):
#include <iostream> #include <vector> #include <cstdlib> #include <algorithm> #include <time.h> #include <cstdio> using namespace std; int main(){ int n; cin >> n; vector< pair<int,int> > v; for(int i = 0 ; i < n ; i++){ int a,b; cin >> a >> b; v.push_back(make_pair(-b,a)); } sort(v.begin(),v.end()); cout << v[0].second << " " << v[0].first * (-1) << endl; }
Problem: 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 Solution (in CPP):
#include<stdio.h> #include<algorithm> using namespace std; pair<int,int> v[20]; int main(){ int a;scanf("%d",&a); for(int i=0;i<a;i++){ int b,c; scanf("%d%d",&b,&c); v[i]=make_pair(-c,b); }std::sort(v,v+a); printf("%d %d\n",v[0].second,-v[0].first); }
Problem: 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 Solution (in CPP):
#include <cstdio> using namespace std; int main(){ int n, a, b, maxv, maxi; scanf("%d", &n); maxv = -1, maxi = 0; for (int i = 0; i < n; i++) { scanf("%d %d", &a, &b); if (b > maxv) { maxv = b; maxi = a; } if (b == maxv && maxi > a) maxi = a; } printf("%d %d\n", maxi, maxv); return 0; }
Problem: 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 Solution (in JAVA):
import java.util.Scanner; class Main{ public static void main(String[] a){ Scanner scan = new Scanner(System.in); while (scan.hasNext()){ int n = 0; n = scan.nextInt(); int bigkekka = -1; int bigsen = -1; for(int i = 0; i < n; i++){ int num = scan.nextInt(); int result = scan.nextInt(); if(result > bigkekka){ bigkekka = result; bigsen = num; }else if (bigkekka == result){ bigsen = Math.min(bigsen, num); } } System.out.println(bigsen + " " + bigkekka); } } }
Problem: 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 Solution (in CPP):
#include <iostream> #include <vector> #include <algorithm> #include <stack> #include <string> #include <map> #include <functional> #include <cmath> #include <cstdio> using namespace std; int main(){ int n; cin >> n; map<int, int> point; vector<int> tmp(n); for(int i = 0; i < n; i++){ int a, v; cin >> a >> v; point[a] = v; tmp[i] = v; } sort(tmp.begin(), tmp.end(), greater<int>()); for(int i = 1; i <= n; i++){ if(point[i] == tmp[0]){ cout << i << " " << point[i] << endl; return 0; } } }
Problem: 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 Solution (in CPP):
#include<stdio.h> int main(){ int x,y,n; int X=0,Y=0; scanf("%d",&n); for(int i=0;i<n;i++) { scanf("%d %d",&x,&y); if(i==0){Y=y;X=x;} if(Y==y&&x<X){X=x;Y=y;} else if(Y<y){X=x;Y=y;} } printf("%d %d\n",X,Y); return 0; }