238 afișări Tudurachi Călin (colan007) 27.09.2023 www.pbinfo.ro
Etichete: nicio etichetă

#include <fstream>
#include <climits>
using namespace std;

ifstream cin (“ciocolata.in”);
ofstream cout (“ciocolata.out”);

int v502502;
long long sum502502;

int main(){ int n, m, solx1, soly1, solx2, soly2;

long long maxx = LLONG_MIN , sol; cin >> n >> m; for (int i = 1; i <= n; ++i) for (int j = 1; j <= m; ++j) cin >> v[i][j]; for (int i = 1; i <= m; ++i) for (int j = 1; j <= n; ++j) sum[j][i] = sum[j-1][i] + v[j][i]; int x1, y1, x2, y2; for (int i = 1; i <= n; ++i){ x1 = i; for (int j = i; j <= n; ++j){ sol = 0; x2 = j; y1 = 1; y2 = 0; for (int k = 1; k <= m; ++k){ long long x = sum[j][k] – sum[i-1][k]; if (x > sol + x){ y1 = y2 = k; sol = x; } else{ sol = sol + x; y2++; } if (sol > maxx){ maxx = sol; solx1 = x1; solx2 = x2; soly1 = y1; soly2 = y2; } } } } cout << maxx << “\n”; cout << solx1 << “ “ << soly1 << “ “ << solx1 << “ “ << soly2 << “\n”; cout << solx2 << “ “ << soly1 << “ “ << solx2 << “ “ << soly2; return 0; }

238 afișări Tudurachi Călin (colan007) 27.09.2023 www.pbinfo.ro