Codeforces Beta Round 2 2A - Winner Solution


 

Problem Link  :   https://codeforces.com/problemset/problem/2/A

Solution in C++:

  1. /// La ilaha illellahu muhammadur rasulullah
  2. ///******Bismillahir-Rahmanir-Rahim******///
  3. /// Abul Hasnat Tonmoy
  4. /// Department of CSE,23rd batch
  5. /// Islamic University,Bangladesh
  6. ///**********ALLAH IS ALMIGHTY************///
  7. #include <bits/stdc++.h>
  8. using namespace std;
  9. int32_t main() {
  10. ios_base::sync_with_stdio(0);
  11. cin.tie(0);
  12. int n , a[1001] ;
  13. string s[1001] ;
  14. map< string , int > mp1 , mp2 ;
  15. cin >> n ;
  16. for ( int i = 0 ; i < n ; i++){
  17. cin >> s[i] >> a[i] ;
  18. mp1[s[i]] +=a[i] ;
  19. }
  20. int mx = 0 ;
  21. for ( int i = 0 ; i < n ; i++ ) {
  22. mx = max( mx , mp1[s[i]]) ;
  23. }
  24. for ( int i = 0 ; i < n ; i++ ) {
  25. mp2[s[i]] += a[i] ;
  26. if ( mp1[s[i]] >= mx && mp2[s[i]] >= mx ) {
  27. cout << s[i] << endl;
  28. break ;
  29. }
  30. }
  31. return 0 ;
  32. }

No comments

Most View Post

Recent post

Codeforces Round 971 (Div. 4) 2009C. The Legend of Freya the Frog Solution

  Problem Link    https://codeforces.com/contest/2009/problem/C S olution in C++: /// Author : AH_Tonmoy #include < bits / stdc ++. h ...

Powered by Blogger.