#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef double db;
const int N = 2e5 + 50;
const int M = 1e5 + 50;
const int Mod = 1e9 + 7;
inline int read()
{
int x = 0, f = 1;
char ch = getchar();
while (ch < '0' || ch > '9')
{
if (ch == '-')
f = -1;
ch = getchar();
}
while (ch >= '0' && ch <= '9')
{
x = (x << 1) + (x << 3) + (ch ^ 48);
ch = getchar();
}
return x * f;
}
int t, n, k;
int w[N], v[N];
signed main()
{
freopen("ball.in", "r", stdin);
freopen("ball.out", "w", stdout);
t = read();
while (t--)
{
n = read(), k = read();
for (int i = 1; i <= n; ++i)
w[i] = read();
sort(w + 1, w + n + 1);
for (int i = 1; i <= k; ++i)
v[i] = read() - 1;
sort(v + 1, v + k + 1);
ll res = 0;
int r = n;
for (int i = 1; i <= k; ++i)
{
if (!v[i])
res += w[r] * 2;
else
res += w[r];
r--;
}
for (int i = 1; i <= k; ++i)
{
if (!v[i])
continue;
res += w[r - v[i] + 1];
r -= v[i];
}
printf("%lld\n", res);
}
return 0;
}
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef double db;
#define int long long
const int N = 1e2 + 50;
const int M = 1e3 + 50;
const int Mod = 1e9 + 7;
inline int read()
{
int x = 0, f = 1;
char ch = getchar();
while (ch < '0' || ch > '9')
{
if (ch == '-')
f = -1;
ch = getchar();
}
while (ch >= '0' && ch <= '9')
{
x = (x << 1) + (x << 3) + (ch ^ 48);
ch = getchar();
}
return x * f;
}
int t, n, m;
int a[N], b[N];
int f[M];
// int q[M];
signed main()
{
freopen("group.in", "r", stdin);
freopen("group.out", "w", stdout);
t = read();
while (t--)
{
n = read(), m = read();
for (int i = 1; i <= n; ++i)
a[i] = read();
for (int i = 1; i <= n; ++i)
b[i] = read();
memset(f, 0, sizeof(f));
f[0] = 1;
for (int i = 1; i <= n; ++i)
{
for (int r = m; r > m - a[i]; --r)
{
for (int j = r; j >= a[i]; j -= a[i])
{
for (int k = 1; k <= b[i]; ++k)
{
if (j >= k * a[i])
f[j] = (f[j] + f[j - k * a[i]]) % Mod;
else
break;
}
}
}
}
int res = 0;
for (int i = 1; i <= m; ++i)
{
res = (res + f[i]) % Mod;
}
printf("%lld\n", res);
}
return 0;
}
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef double db;
const int N = 3e2 + 50;
const int M = 1e5 + 50;
const int Mod = 1e9 + 7;
inline int read()
{
int x = 0, f = 1;
char ch = getchar();
while (ch < '0' || ch > '9')
{
if (ch == '-')
f = -1;
ch = getchar();
}
while (ch >= '0' && ch <= '9')
{
x = (x << 1) + (x << 3) + (ch ^ 48);
ch = getchar();
}
return x * f;
}
int t, n;
int v[N];
int a[N][N], f[N][N];
int main()
{
freopen("match.in", "r", stdin);
freopen("match.out", "w", stdout);
t = read();
while (t--)
{
n = read();
for (int i = 1; i <= n; ++i)
v[i] = read();
for (int i = 1; i <= n; ++i)
{
for (int j = 1; j <= n; ++j)
{
a[i][j] = read();
}
}
memset(f, 0, sizeof(f));
for (int i = 0; i <= n; ++i)
f[i][i] = i;
for (int len = 1; len <= n; ++len)
{
for (int l = 1; l <= n - len + 1; ++l)
{
int r = l + len - 1;
for (int k = l; k < r; ++k)
{
if (a[f[l][k]][f[k + 1][r]])
{
if (v[f[l][r]] < v[f[l][k]])
{
f[l][r] = f[l][k];
}
}
else
{
if (v[f[l][r]] < v[f[k + 1][r]])
{
f[l][r] = f[k + 1][r];
}
}
}
}
}
printf("%d\n", v[f[1][n]]);
}
return 0;
}
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef double db;
const int N = 2e5 + 50;
const int M = 1e5 + 50;
const int Mod = 1e9 + 7;
inline int read()
{
int x = 0, f = 1;
char ch = getchar();
while (ch < '0' || ch > '9')
{
if (ch == '-')
f = -1;
ch = getchar();
}
while (ch >= '0' && ch <= '9')
{
x = (x << 1) + (x << 3) + (ch ^ 48);
ch = getchar();
}
return x * f;
}
int t, n, k, MX;
int a[N];
priority_queue<int, vector<int>, greater<int>> s, CLEAR;
bool check(int x)
{
s = CLEAR;
for (int i = 1; i < k; ++i)
s.push(a[i]);
for (int i = k; i <= n; ++i)
{
s.push(a[i]);
if (x >= s.top())
x += s.top();
else
return false;
s.pop();
if (x >= MX)
return true;
}
for (int i = 1; i < k; ++i)
{
if (x >= s.top())
x += s.top();
else
return false;
s.pop();
if (x >= MX)
return true;
}
return true;
}
signed main()
{
freopen("monster.in", "r", stdin);
freopen("monster.out", "w", stdout);
t = read();
while (t--)
{
n = read(), k = read();
MX = 0;
for (int i = 1; i <= n; ++i)
a[i] = read(), MX = max(MX, a[i]);
int l = 0, r = 1e9, ans = Mod;
while (l < r)
{
int mid = l + r >> 1;
if (check(mid))
{
ans = min(ans, mid);
r = mid;
}
else
{
l = mid + 1;
}
}
printf("%d\n", ans);
}
return 0;
}
标签:ch,const,7.28,int,EOI,long,while,getchar
From: https://www.cnblogs.com/R-V-G/p/17588704.html