QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#94062 | #6135. Books | CSU2023# | AC ✓ | 32ms | 3868kb | C++14 | 1.1kb | 2023-04-05 09:46:24 | 2023-04-05 09:46:24 |
Judging History
answer
#include <bits/stdc++.h>
template <class T>
inline void read(T &res)
{
char ch; bool flag = false; res = 0;
while (ch = getchar(), !isdigit(ch) && ch != '-');
ch == '-' ? flag = true : res = ch ^ 48;
while (ch = getchar(), isdigit(ch))
res = res * 10 + ch - 48;
flag ? res = -res : 0;
}
template <class T>
inline void put(T x)
{
if (x > 9)
put(x / 10);
putchar(x % 10 + 48);
}
template <class T>
inline void CkMin(T &x, T y) {x > y ? x = y : 0;}
typedef long long ll;
const int N = 1e5 + 5;
const int Maxn = 1e9;
int a[N], mx = Maxn;
int T_data, n, m;
int main()
{
read(T_data);
while (T_data--)
{
read(n); read(m);
int cnt = 0;
for (int i = 1; i <= n; ++i)
{
read(a[i]);
if (a[i] == 0)
++cnt;
}
if (n == m)
puts("Richman");
else if (cnt > m)
puts("Impossible");
else
{
ll sum = 0;
int mx = Maxn;
for (int i = 1; i <= n; ++i)
{
if (a[i] == 0)
continue ;
if (cnt < m)
{
++cnt;
sum += a[i];
}
else
CkMin(mx, a[i]);
}
put(sum + mx - 1), putchar('\n');
}
}
}
详细
Test #1:
score: 100
Accepted
time: 2ms
memory: 3404kb
input:
4 4 2 1 2 4 8 4 0 100 99 98 97 2 2 10000 10000 5 3 0 0 0 0 1
output:
6 96 Richman Impossible
result:
ok 4 lines
Test #2:
score: 0
Accepted
time: 32ms
memory: 3868kb
input:
10012 1 0 2 3 2 0 1 0 2 1 0 0 100000 99999 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000...
output:
1 0 Impossible 99999999999999 192 80 Richman 97 460 Richman 24 163 98 30 15 Richman Richman Richman 65 Richman Richman 450 98 44 349 34 513 28 161 297 Richman Richman Richman 147 274 2 160 76 58 91 130 3 Richman 175 32 15 Richman 21 26 Richman 65 Richman 247 356 Richman Richman 60 312 62 276 Richman...
result:
ok 10012 lines
Test #3:
score: 0
Accepted
time: 28ms
memory: 3800kb
input:
10012 1 0 2 3 2 0 1 0 2 1 0 0 100000 99999 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000...
output:
1 0 Impossible 99999999999999 Richman Impossible 697 123 Richman Impossible Richman 335 Richman Impossible Richman 486 Richman Impossible 57 41 Richman Impossible 42 Richman Richman 99 106 Richman Richman Impossible Richman Richman Richman Impossible 164 26 Richman 43 Richman Richman Richman Impossi...
result:
ok 10012 lines