fork download
  1. //longlong5a6
  2. #include <bits/stdc++.h>
  3. #define pii pair<int,int>
  4. #define F first
  5. #define S second
  6. #define bit(i, x)((x >> i) & 1)
  7. #define sobit(i) __builtin_popcount((int)(i))
  8. #define pb push_back
  9. #define all(x) x.begin(),x.end()
  10. #define vi vector<int>
  11. #define For(i,x,n) for(int (i)=(int)(x);(i)<=(int)(n);(i)++)
  12. #define round(m,n) setprecision((int)m) << fixed << double(n)
  13. #define down "\n"
  14. #define TASK "hexangle"
  15. #define maxn 3001
  16.  
  17. using namespace std;
  18. int a[maxn][maxn];
  19. int m;
  20.  
  21. void work(int k)
  22. {
  23. if(k == 1)
  24. {
  25. return;
  26. }
  27. int sub;
  28. if(k == 2)
  29. {
  30. sub = 1;
  31. }
  32. else sub = ceil(1.0*k/1.5);
  33. work(sub);
  34. For(i, 1, m-k+1)
  35. {
  36. For(j, 1, i)
  37. {
  38. int lim = i - sub + k;
  39. a[i][j] = max(a[i][j], max(a[lim][j], a[lim][j-sub+k]));
  40. }
  41. }
  42.  
  43. }
  44.  
  45. int main()
  46. {
  47. ios_base::sync_with_stdio(0);
  48. cin.tie();
  49. cout.tie();
  50. if (fopen("in.txt","r"))
  51. {
  52. freopen("in.txt","r",stdin);
  53.  
  54. }
  55. if (fopen(TASK".INP","r"))
  56. {
  57. freopen(TASK".INP","r",stdin);
  58. freopen(TASK".OUT","w",stdout);
  59. }
  60. int k;
  61. cin>>m>>k;
  62. For(i,1,m)
  63. {
  64. For(j,1,i) cin>>a[i][j];
  65. }
  66. work(k);
  67. long long res=0;
  68. For(i,1,m-k+1)
  69. {
  70. For(j,0,i) res+=a[i][j];
  71. }
  72. cout<<res;
  73. }
  74.  
Success #stdin #stdout 0.01s 5272KB
stdin
Standard input is empty
stdout
Standard output is empty