新鲜的数学题来咯
题意:有两种操作,ai-=1,aj-=1,ai-1+=1,aj+1+=1与ai-=1,aj-=1,ai+1+=1,aj+2+=1,但是第一种操作只能用于第k行之外的行,而第二种操作则只能用于第k行,两种操作都可以用任意次
思路:首先分析这两种操作,拥有数学头脑的人一眼就看出来了,第一种操作是守恒的,而第二种是不守恒的,因为它们一个平衡,一个不平衡,在某些值,比如i*ai的累和就会不相等,且累和之间的差值就是不守恒的操作的使用次数(仔细想想,和贪心不等式有点类似,不过构造的成分更多)
#include<iostream>
#include<cstring>
#include<cstdio>
#include<queue>
#include<map>
#include<set>
#include<vector>
#include<algorithm>
#include<string>
#include<bitset>
#include<cmath>
#include<array>
#include<atomic>
#include<sstream>
#include<stack>
#include<iomanip>
//#include<bits/stdc++.h>
//#define int ll
#define IOS std::ios::sync_with_stdio(false);std::cin.tie(0);
#define pb push_back
#define endl '\n'
#define x first
#define y second
#define Endl endl
#define pre(i,a,b) for(int i=a;i<=b;i++)
#define rep(i,b,a) for(int i=b;i>=a;i--)
#define si(x) scanf("%d", &x);
#define sl(x) scanf("%lld", &x);
#define ss(x) scanf("%s", x);
#define YES {puts("YES");return;}
#define NO {puts("NO"); return;}
#define all(x) x.begin(),x.end()
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int, int> PII;
typedef pair<int, PII> PIII;
typedef pair<char, int> PCI;
typedef pair<int, char> PIC;
typedef pair<double, double> PDD;
typedef pair<ll, ll> PLL;
const int N = 300010, M = 2 * N, B = N, MOD = 998244353;
const double eps = 1e-8;
const int INF = 0x3f3f3f3f;
const ll LLINF = 0x3f3f3f3f3f3f3f3f;
int dx[4] = { -1,0,1,0 }, dy[4] = { 0,1,0,-1 };
int n, m, k;
ll sum[N];
vector<ll> a[N];
ll gcd(ll a, ll b) { return b ? gcd(b, a % b) : a; }
ll lowbit(ll x) { return x & -x; }
ll qmi(ll a, ll b, ll MOD) {
ll res = 1;
while (b) {
if (b & 1) res = res * a % MOD;
a = a * a % MOD;
b >>= 1;
}
return res;
}
inline void init() {}
void slove()
{
si(n); si(m);
pre(i, 1, n) a[i].clear(), sum[i] = 0;
int x;
pre(i, 1, n) {
pre(j, 1, m) {
cin >> x;
a[i].push_back(x);
}
}
ll mx = -LLINF, mn = LLINF;
pre(i, 1, n)
{
pre(j, 0, m - 1)
if (i)sum[i] += (j + 1) * a[i][j];
else sum[i] += 1ll * (j + 1) * a[i][j];
mx = max(mx, sum[i]);
mn = min(mn, sum[i]);
}
pre(i, 1, n)
{
if (sum[i] == mx) {
printf("%lld %lld\n", i, mx - mn);
}
}
return;
}
signed main()
{
//IOS;
int _;
si(_);
//_ = 1;
init();
while (_--)
{
slove();
}
return 0;
}