Submission #852226

#TimeUsernameProblemLanguageResultExecution timeMemory
852226Trisanu_DasZemljište (COCI22_zemljiste)C++17
0 / 70
1 ms344 KiB
#include <bits/stdc++.h> using namespace std; int main(){ int r, s, a, b; cin >> r >> s >> a >> b; int v[r][s]; for(int i = 0; i < r; i++) for(int j = 0; j < s; j++) cin >> v[i][j]; for(int i = 1; i < r; i++) for(int j = 0; j < s; j++) v[i][j] += v[i - 1][j]; int ans = INT_MAX; for(int i = 0; i < r; i++){ for(int j = i; j < r; j++){ int pos = 0, sum = 0; for(int k = 0; k < s; k++){ sum += v[j][k] - v[i - 1][k]; while(sum > b && pos <= k){ ans = min(ans, abs(b - sum) + abs(sum - a)); sum -= v[j][pos] - v[i - 1][pos]; pos++; } if(a <= sum && b >= sum){ cout << b - a << '\n'; return 0; } ans = min(ans, abs(b - sum) + abs(sum - a)); } } } cout << ans << '\n'; }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...