fork download
  1. #include<bits/stdc++.h>
  2. using namespace std;
  3.  
  4. #define ll long long
  5.  
  6. int main(){
  7. ios_base::sync_with_stdio(false);
  8. cin.tie(NULL);
  9. ll n,ans=-1,cnt=1;
  10. cin>>n;
  11. vector<ll>v(n);
  12. for(auto &i:v)cin>>i;
  13. unordered_map<ll,ll>mp;
  14. for(auto &i:v){
  15. ll a=i,s=0;
  16. while(a!=0){
  17. s+=a%10;
  18. a/=10;
  19. }
  20. if(mp.find(s)!=mp.end()){
  21. if(mp[s]+i>ans){
  22. ans=mp[s]+i;
  23. cnt=1;
  24. }
  25. else if(mp[s]+i==ans)cnt++;
  26. if(mp[s]<i)mp[s]=i;
  27. }
  28. else mp[s]=i;
  29. }
  30.  
  31. cout<<ans<<" "<<cnt<<"\n";
  32. return 0;
  33. }
Success #stdin #stdout 0.01s 5248KB
stdin
Standard input is empty
stdout
0 72702