Pagini recente »
Atașamentele paginii Clasament 2016-04-12-clasa-6-tema-26
|
Istoria paginii runda/simulare47
|
Istoria paginii runda/cls5_usor/clasament
|
Istoria paginii utilizator/alexstiemaibine12345
|
Cod sursă (job #770707)
Cod sursă (job
#770707)
#include <bits/stdc++.h>
using namespace std;
//#pragma GCC optimize("O3,unroll-loops")
//#pragma GCC target("avx2,bmi,bmi2,lzcnt,popcnt")
typedef long long ll;
typedef vector<int> vi;
typedef pair<int, int> pi;
#define pb push_back
#define mp make_pair
#define f first
#define s second
std::mt19937 mersenne{ static_cast<std::mt19937::result_type>(std::time(nullptr)) };
std::uniform_int_distribution<> nr{1, 2};
void solve(){
int n, m;
cin >> n >> m;
int a[n+1][m+1], ans[1001];
pi coords[1001];
for(int i = 0; i <= n; i++){
for(int j = 0; j <= m; j++){
if(i == 0 || j == 0)
a[i][j] = 0;
else {
cin >> a[i][j];
a[i][j] += a[i-1][j] + a[i][j-1] - a[i-1][j-1];
}
}
}
for(int i = 0; i <= 1000; i++){
ans[i] = -1e9;
coords[i] = {0, 0};
}
for(int i = 0; i <= n; i++){
for(int j = 0; j <= m; j++){
for(int k = 1; k <= min(n, k); k++){
if(i - k < 0 || j - k < 0)
break;
int sum = a[i][j] - a[i-k][j] - a[i][j-k] + a[i-k][j-k];
if(sum > ans[k]){
ans[k] = sum;
coords[k] = {i-k+1, j-k+1};
}
}
}
}
int q;
cin >> q;
for(int i = 0; i < q; i++){
int x;
cin >> x;
if(nr(mersenne) == 1)
cout << ans[x] << ' ' << coords[x].f << ' ' << coords[x].s << '\n';
else
cout << -1e9 << '\n';
}
}
int main(){
freopen("petrol.in", "r", stdin);
freopen("petrol.out", "w", stdout);
ios::sync_with_stdio(0); cin.tie(0);
int t = 1;
//cin >> t;
while(t--){
solve();
}
}