Submission #852226

# Submission time Handle Problem Language Result Execution time Memory
852226 2023-09-21T13:01:16 Z Trisanu_Das Zemljište (COCI22_zemljiste) C++17
0 / 70
1 ms 344 KB
#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 time Memory Grader output
1 Incorrect 1 ms 344 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 1 ms 344 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 1 ms 344 KB Output isn't correct
2 Halted 0 ms 0 KB -