fork download
  1. #include<iostream>
  2. #include<vector>
  3. struct test{
  4. int a[101][101];
  5. int n;
  6. };
  7. using namespace std;
  8. int main()
  9. {
  10.  
  11. std::ios_base::sync_with_stdio(false);
  12. int t,pl=1,s=0;
  13. vector<test> v;
  14. test tc;
  15. cin>>t;
  16. for(int i=0;i<t;i++)
  17. { cin>>tc.n;
  18.  
  19. for(int j=0;j<tc.n;j++)
  20. for(int x=0;x<=j;x++)
  21. cin>>tc.a[j][x];
  22.  
  23. v.push_back(tc);
  24. }
  25.  
  26. int maxi;
  27.  
  28. for(int i=0;i<t;i++)
  29. {
  30. s=0;
  31. maxi = v.at(i).a[0][0];
  32. for(int j=1;j<v.at(i).n;j++)
  33. {
  34. maxi = v.at(i).a[j][0];
  35. for(int x=0;x<=j;x++)
  36. {
  37. if(v.at(i).a[j][x]>maxi)
  38. maxi=v.at(i).a[j][x];
  39. }
  40.  
  41. s+=maxi;
  42.  
  43. }
  44.  
  45.  
  46. cout<<s<<endl;
  47. }
  48.  
  49.  
  50.  
  51.  
  52.  
  53.  
  54.  
  55.  
  56. return 0;
  57. }
  58.  
Success #stdin #stdout 0s 3588KB
stdin
2
3
1
2 1
1 2 3
4 
1 
1 2 
4 1 2
2 3 1 1 
stdout
5
9