QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#309177#6135. BooksAlex_WeiAC ✓209ms4400kbC++141.4kb2024-01-20 15:23:222024-01-20 15:23:24

Judging History

This is the latest submission verdict.

  • [2024-01-20 15:23:24]
  • Judged
  • Verdict: AC
  • Time: 209ms
  • Memory: 4400kb
  • [2024-01-20 15:23:22]
  • Submitted

answer

#include <bits/stdc++.h>
using namespace std;

using ll = long long;
using pii = pair<int, int>;
using pll = pair<ll, ll>;
using pdi = pair<double, int>;
using pdd = pair<double, double>;
using ull = unsigned long long;
using LL = __int128_t;

#define ppc(x) __builtin_popcount(x)
#define clz(x) __builtin_clz(x)

bool Mbe;

constexpr int mod = 1e9 + 7;
void addt(int &x, int y) {
  x += y, x >= mod && (x -= mod);
}
int add(int x, int y) {
  return x += y, x >= mod && (x -= mod), x;
}

// ---------- templates above ----------

constexpr int N = 1e5 + 5;

int n, m, a[N];

void solve() {
  cin >> n >> m;
  ll ans = 0;
  for(int i = 1; i <= n; i++) {
    cin >> a[i];
    if(!a[i]) m--;
  }
  if(m < 0) {
    cout << "Impossible\n";
    return;
  }
  int mn = 1e9 + 7;
  for(int i = 1; i <= n; i++) {
    if(!a[i]) continue;
    if(m) ans += a[i], m--;
    else mn = min(mn, a[i]);
  }
  if(mn <= 1e9) cout << ans + mn - 1 << "\n";
  else cout << "Richman\n";
}

bool Med;
signed main() {
  fprintf(stderr, "%.3lf MB\n", (&Mbe - &Med) / 1048576.0);
  // ios::sync_with_stdio(0), cin.tie(0), cout.tie(0);
  #ifdef ALEX_WEI
    FILE* IN = freopen("1.in", "r", stdin);
    FILE* OUT = freopen("1.out", "w", stdout);
  #endif
  int T = 1;
  cin >> T;
  while(T--) solve();
  fprintf(stderr, "%.3lf ms\n", 1e3 * clock() / CLOCKS_PER_SEC);
  return 0;
}

/*
g++ a.cpp -o a -std=c++14 -O2 -DALEX_WEI
*/

詳細信息

Test #1:

score: 100
Accepted
time: 0ms
memory: 3976kb

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: 209ms
memory: 4364kb

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: 207ms
memory: 4400kb

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