fork download
  1. #include <bits/stdc++.h>
  2. using ll=long long int;
  3. using namespace std;
  4. int fun(ll n){
  5. int sum=0;
  6. while(n!=0){
  7. sum+=(n%10);
  8. n=n/10;
  9. }
  10. return sum;
  11. }
  12. int main()
  13. {
  14.  
  15. vector<ll>a={8, 8, 3, 8, 6, 8, 1, 8, 2};
  16. int n=a.size();
  17. vector<int>p(1000,-1);
  18. ll ans=-1;
  19. ll y=-1;
  20. for(int i=0;i<n;i++){
  21. ll x=fun(a[i]);
  22.  
  23. if(p[x]!=-1){
  24. ans=max(ans,a[i]+p[x]);
  25. y=x;
  26. }
  27. if(a[i]>p[x]){
  28. p[x]=a[i];
  29. }
  30. // cout<<x<<" "<<p[x]<<" "<<ans<<endl;
  31. }
  32. map<pair<int,int>,int>p1;
  33. cout<<ans<<" "<<y<<endl;
  34. int ans2=0;
  35.  
  36. for(int i=0;i<n;i++){
  37. ll x=fun(a[i]);
  38. if(p1[{ans-a[i],x}]!=0&&x==y){
  39. ans2=ans2+p1[{ans-a[i],x}];
  40. }
  41. p1[{a[i],x}]++;
  42. // cout<<x<<" "<<p[x]<<" "<<ans<<endl;
  43. }
  44. if(ans==-1){
  45. ans2=-1;
  46. }
  47. cout<<ans2<<endl;
  48. return 0;
  49. }
Success #stdin #stdout 0s 5320KB
stdin
Standard input is empty
stdout
16 8
10