Codeforces Beta Round 2 2A - Winner Solution
Problem Link : https://codeforces.com/problemset/problem/2/A
Solution in C++:
- /// La ilaha illellahu muhammadur rasulullah
- ///******Bismillahir-Rahmanir-Rahim******///
- /// Abul Hasnat Tonmoy
- /// Department of CSE,23rd batch
- /// Islamic University,Bangladesh
- ///**********ALLAH IS ALMIGHTY************///
- #include <bits/stdc++.h>
- using namespace std;
- int32_t main() {
- ios_base::sync_with_stdio(0);
- cin.tie(0);
- int n , a[1001] ;
- string s[1001] ;
- map< string , int > mp1 , mp2 ;
- cin >> n ;
- for ( int i = 0 ; i < n ; i++){
- cin >> s[i] >> a[i] ;
- mp1[s[i]] +=a[i] ;
- }
- int mx = 0 ;
- for ( int i = 0 ; i < n ; i++ ) {
- mx = max( mx , mp1[s[i]]) ;
- }
- for ( int i = 0 ; i < n ; i++ ) {
- mp2[s[i]] += a[i] ;
- if ( mp1[s[i]] >= mx && mp2[s[i]] >= mx ) {
- cout << s[i] << endl;
- break ;
- }
- }
- return 0 ;
- }
No comments