# 2. 题解

23333 纯卡常过的。

$1000$的数据从 TLE 卡到 AC，关键跑的还挺快的，最慢的点 300+ms（原本 1000ms 都过不了）

#include <bits/stdc++.h>

#define NS (1005)

using namespace std;

template <typename _Tp> inline void IN(_Tp& dig)
{
char c; bool flag = 0; dig = 0;
while (c = getchar(), !isdigit(c));
while (isdigit(c)) dig = dig * 10 + c - '0', c = getchar();
}

int n, m, p, coin[NS][NS], cost[NS], f[NS];

int main (int argc, char const* argv[])
{
IN(n), IN(m), IN(p);
for (int i = 1; i <= n; i += 1)
for (int j = 1; j <= m; j += 1)
IN(coin[i][j]);
for (int i = 1; i <= n; i += 1) IN(cost[i]);
for (int i = 1; i <= m; i += 1) f[i] = INT_MIN;
for (int i = 1, tmp; i <= m; i += 1)
for (int j = 1; j <= n; j += 1)
{
tmp = f[i - 1] - cost[j];
for (int k = 0, t; k < p && i + k <= m; k += 1)
{
t = (j + k - 1) % n + 1;
tmp += coin[t][i + k];
f[i + k] = max(f[i + k], tmp);
}
}
printf("%d\n", f[m]);
return 0;
}


t = (j + k - 1) % n + 1;


t = j + k > n ? j + k - n : j + k;


#define REG register
for (REG int i = 1; i <= n; i += 1)


#pragma GCC optimize("Ofast,no-stack-protector")

#include <bits/stdc++.h>

#define REG register
#define NS (1005)

using namespace std;

template <typename _Tp> inline void IN(_Tp& dig)
{
char c; bool flag = 0; dig = 0;
while (c = getchar(), !isdigit(c));
while (isdigit(c)) dig = dig * 10 + c - '0', c = getchar();
}

int n, m, p, coin[NS][NS], cost[NS], f[NS];

int main (int argc, char const* argv[])
{
IN(n), IN(m), IN(p);
for (REG int i = 1; i <= n; i += 1)
for (REG int j = 1; j <= m; j += 1)
IN(coin[i][j]);
for (REG int i = 1; i <= n; i += 1) IN(cost[i]);
for (REG int i = 1; i <= m; i += 1) f[i] = INT_MIN;
for (REG int i = 1, tmp; i <= m; i += 1)
for (REG int j = 1; j <= n; j += 1)
{
tmp = f[i - 1] - cost[j];
for (REG int k = 0, t; k < p && i + k <= m; k += 1)
{
t = j + k > n ? j + k - n : j + k;
tmp += coin[t][i + k];
f[i + k] = max(f[i + k], tmp);
}
}
printf("%d\n", f[m]);
return 0;
}