Advertisement
Guest User

Untitled

a guest
Feb 26th, 2020
86
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.08 KB | None | 0 0
  1. #include <bits/stdc++.h>
  2. using namespace std;
  3. ifstream f("comori.in");
  4. ofstream g("comori.out");
  5. int a[202][202],n,m;
  6. void bord()
  7. {
  8.  
  9. }
  10. int suma(int x,int y)
  11. {
  12. int s=0;
  13. s=a[x][y];
  14. while(x<=n)
  15. {
  16. bool ok=false;
  17. if(a[x+1][y]>=a[x+1][y-1])
  18. ok=true;
  19. if(ok==true)
  20. {
  21. if(a[x+1][y]>=a[x+1][y+1])
  22. {
  23. s+=a[x+1][y];
  24. }
  25. else
  26. {
  27. s+=a[x+1][y+1];
  28. y++;
  29.  
  30. }
  31. }
  32. if(ok==false)
  33. if(a[x+1][y-1]>=a[x+1][y+1])
  34. {
  35. s+=a[x+1][y-1];
  36. y--;
  37. }
  38. else
  39. {
  40. s+=a[x+1][y+1];
  41. y++;
  42. }
  43. x++;
  44. }
  45. return s;
  46. }
  47. int main()
  48. {
  49. int i,j,s_max=0;
  50. f>>n>>m;
  51. for(i=1; i<=n; i++)
  52. for(j=1; j<=m; j++)
  53. f>>a[i][j];
  54. for(i=1; i<=n; i++)
  55. {
  56. int s=suma(i,1);
  57. g<<s<<endl;
  58. if(s_max<s)
  59. s_max=s;
  60. }
  61. //g<<s_max;
  62. return 0;
  63. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement