• 微信公众号：美女很有趣。 工作之余，放松一下，关注即送10G+美女照片！

2周前 (04-29) 9次浏览

# 原题链接

### A题 Red and Blue Beans

#### 代码：

``````typedef long long LL;

const int N = 200010;

int main()
{
int T;
scanf("%d", &T);
while (T -- )
{
int a, b, c;
scanf("%d%d%d", &a, &b, &c);

int res = abs(a - b);
if (res == 0) puts("YES");
else
{
int l = min(a, b);
int x = res / l;
int y = res % l;
if (y >= 1) x ++ ;
if (x <= c) puts("YES");
else puts("NO");
}
}

return 0;
}
``````

### B题 The Cake Is a Lie

sb题，找规律找了半天发现只有一种情况，直接判断就行。

#### 代码：

``````typedef long long LL;

const int N = 110;

int n, m, k;

int main()
{
int T;
scanf("%d", &T);
while (T -- )
{
cin >> n >> m >> k;

int res = n - 1 + (m - 1) * n;
if (res == k) puts("YES");
else puts("NO");
}

return 0;
}
``````

### C题 Berland Regional

#### 代码：

``````typedef long long LL;

const int N = 200010;

int n, m, k;
int g[N], w[N];
vector<LL> s[N]; // 前缀和数组
LL res[N];

bool cmp(LL a, LL b) // 重载比较函数
{
return a > b;
}

int main()
{
int T;
scanf("%d", &T);
while (T -- )
{
scanf("%d", &n);
for (int i = 1; i <= n; i ++ ) res[i] = 0, s[i].clear();
for (int i = 1; i <= n; i ++ ) scanf("%d", &g[i]);
for (int i = 1; i <= n; i ++ ) scanf("%d", &w[i]);

for (int i = 1; i <= n; i ++ ) s[g[i]].push_back((LL)w[i]);
for (int i = 1; i <= n; i ++ ) sort(s[i].begin(), s[i].end(), cmp);

for (int i = 1; i <= n; i ++ )
for (int j = 1; j < s[i].size(); j ++ )
s[i][j] = s[i][j - 1] + s[i][j];

for (int i = 1; i <= n; i ++ )
for (int j = 1; j <= s[i].size(); j ++ )
{
int t = s[i].size();
res[j] += s[i][t - t % j - 1]; // 下标从0开始
}

for (int i = 1; i <= n; i ++ ) printf("%lld ", res[i]);
printf("n");
}

return 0;
}
``````

### D题 Maximum Sum of Products

#### 代码：

``````const int N = 5010;

int n, m, k;
LL a[N], b[N];
LL f[N][N]; // f[l][r] 表示将l-r区间反转之后的值是多少
LL s[N];

int main()
{
cin >> n;

for (int i = 1; i <= n; i ++ ) cin >> a[i];
for (int i = 1; i <= n; i ++ ) cin >> b[i];

for (int i = 1; i <= n; i ++ ) s[i] = s[i - 1] + a[i] * b[i];

for (int i = 1; i <= n; i ++ ) f[i][i] = a[i] * b[i]; // 初始化，只翻转一个数

for (int i = n - 1; i >= 1; i -- )
for (int j = i + 1; j <= n; j ++ )
f[i][j] = f[i + 1][j - 1] + a[i] * b[j] + a[j] * b[i];

LL res = s[n];
for (int i = 1; i <= n; i ++ )
for (int j = i + 1; j <= n; j ++ )
res = max(res, f[i][j] + s[i - 1] + s[n] - s[j]);

cout << res << endl;

return 0;
}
``````