Submission #852258

# Submission time Handle Problem Language Result Execution time Memory
852258 2023-09-21T13:47:54 Z Trisanu_Das Zemljište (COCI22_zemljiste) C++17
Compilation error
0 ms 0 KB
#include <bits/stdc++.h>
using namespace std;
#define int long long
 
int arr[505][505];
 
int main(){
	ios_base::sync_with_stdio(0);cin.tie(0);
	int r, s, a, b; cin >> r >> s >> a >> b;
	if(a > b) swap(a, b);
	for(int i = 1; i <= r; i++) for(int j = 1;j <= s; j++) cin >> arr[i][j];
	for(int j = 1; j <= s; j++) for(int i = 1; i <= r;i++) arr[i][j] += arr[i - 1][j];
	int ans = INT_MAX;
	for(int i = 1; i <= r; i++){
		for(int j = i; j <= r; j++){
			int pos = 0, sum = 0;
			for(int k = 1; k <= s; k++){
                sum += arr[j][k] - arr[i - 1][k];
				while(sum > b && pos <= k){
					ans = min(abs(a - sum) + abs(b - sum), ans);
					sum -= arr[j][pos] - arr[i - 1][pos];
					pos++;
				}
				if(a <= sum && b >= sum){
					cout << b - a << '\n'; return 0;
				}
				ans = min(abs(a - sum) + abs(b - sum), ans);
			}
		}
	}
	cout << ans << '\n';
}

Compilation message

cc1plus: error: '::main' must return 'int'