fork download
  1. #include<bits/stdc++.h>
  2. #define ll long long int
  3. #define MOD 1000000007
  4. #define ff first
  5. #define ss second
  6. #define pb push_back
  7. #define ios ios_base::sync_with_stdio(false)
  8. #define mem(a) memset(a,0,sizeof(a));
  9.  
  10. using namespace std;
  11.  
  12. ll a[100010];
  13. vector<ll> v;
  14.  
  15. int main()
  16. {
  17. ios;
  18. ll n,d,ch,x,y;
  19. cin>>n>>d;
  20. ll ans=INT_MIN, ind=-1;
  21. v.clear();
  22. for(ll i=1; i<=n; i++)
  23. {
  24.  
  25. cin>>a[i];
  26. if(a[i]>ans)
  27. {
  28. ans=a[i];
  29. v.clear();
  30. v.pb(i);
  31. }
  32. else if(a[i]==ans)
  33. {
  34. v.pb(i);
  35. }
  36. }
  37.  
  38. while(d--)
  39. {
  40. cin>>ch>>x>>y;
  41. if(ch==1)
  42. {
  43. a[x]+=y;
  44. if(a[x]>ans)
  45. {
  46. ans=a[x];
  47. v.clear();
  48. v.pb(x);
  49. }
  50. else if(a[x]==ans)
  51. {
  52. v.pb(x);
  53. }
  54. }
  55. else if(ch==2)
  56. {
  57. if(a[x]!=a[y])
  58. {
  59. if(a[x]>a[y])
  60. {
  61. if(ans==a[x])
  62. {
  63.  
  64. ans+=a[y];
  65. }
  66. a[x]+=a[y];
  67. if(a[x]>ans)
  68. ans=a[x];
  69. a[y]=0;
  70.  
  71. }
  72. else
  73. {
  74. if(ans==a[y])
  75. {
  76.  
  77. ans+=a[x];
  78. }
  79. a[y]+=a[x];
  80. if(a[y]>ans)
  81. ans=a[y];
  82. a[x]=0;
  83. }
  84. }
  85. }
  86. cout<<ans<<endl;
  87. }
  88. return 0;
  89. }
Runtime error #stdin #stdout 0s 5396KB
stdin
Standard input is empty
stdout
Standard output is empty