QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#236180#3025. Assimilationahsoltan#WA 45ms5488kbC++201.4kb2023-11-03 17:48:522023-11-03 17:48:52

Judging History

你现在查看的是最新测评结果

  • [2023-11-03 17:48:52]
  • 评测
  • 测评结果:WA
  • 用时:45ms
  • 内存:5488kb
  • [2023-11-03 17:48:52]
  • 提交

answer

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

#define x first
#define y second
#define ir(x,a,b) ((a) <= (x) && (x) <= (b))
#define pb push_back
#define all(x) (x).begin(), (x).end()
#define foru(i, n) for (int i = 0; i < n; ++i)
#define fori(i,a,n) for (int i = a; i < n; ++i)

// #ifdef LOCAL
// auto& operator<<(auto&, pair<auto, auto>);
// template<typename T, typename = T::value_type>
// auto& operator<<(auto& o, T x) requires (!same_as<T, string>) {
//   o << "{";
//   string s;
//   for (auto i : x) {
//     o << s << i;
//     s << ", ";
//   }
//   return o << "}";
// }
// auto& operator<<(auto& o, pair<auto, auto> p) {
//   return o << "(" << p.first << ", " << p.second << ")";
// }
// #define debug(x..) cerr << "["#x"]:",[](auto...$){((cerr<<" "<<$),...)<<endl;}(x)
// #else
// #define debug(...) 2137
// #endif

void solve() {
  set<ll> S;
  ll n, k;
  cin >> n >> k;
  ll sum = 0;
  foru (i, n) {
    int x;
    cin >> x;
    sum += x;
    S.insert(x);
  }
  int ct = 0;
  while (k < sum) {
    auto it = S.upper_bound(k);
    if (it == S.begin()) {
      cout << "-1\n";
      return;
    }
    --it;
    ++ct;
    k += (*it);
    sum -= (*it);
    // cout << "taking " << *it << endl;
    // cout << sum << " " << k << endl;
    S.erase(it);
  }
  cout << ct << "\n";
}

int main() {
  ios_base::sync_with_stdio(false); cin.tie(nullptr);
  int z;
  cin >> z;
  while (z--) solve();
  return 0;
}

詳細信息

Test #1:

score: 0
Wrong Answer
time: 45ms
memory: 5488kb

input:

29
9 1
1 1 2 1 1 1 1 1 1
4 1
3 2 1 1
5 316660370
269357435 105688553 346785866 295093544 181703417
6 43402885
39947441 27068237 43810814 44913378 40095941 34779892
22 319594
3815194 3056481 6593888 7315914 6593888 4794774 2561877 5256242 4920603 5256242 3606645 864746 1594265 1235578 2361430 2277526...

output:

-1
2
2
3
-1
10943
4
-1
-1
5858
8
2
-1
5
6566
3
0
-1
-1
-1
-1
7
-1
1
3
-1
5
-1
-1

result:

wrong answer 1st lines differ - expected: '4', found: '-1'