QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#75518#3025. AssimilationBUET_HaloByte#WA 250ms14308kbC++201.7kb2023-02-05 15:52:122023-02-05 15:52:15

Judging History

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

  • [2023-08-10 23:21:45]
  • System Update: QOJ starts to keep a history of the judgings of all the submissions.
  • [2023-02-05 15:52:15]
  • 评测
  • 测评结果:WA
  • 用时:250ms
  • 内存:14308kb
  • [2023-02-05 15:52:12]
  • 提交

answer

#include<bits/stdc++.h>
using namespace std;
#define int long long
void solve() {
    int n;
    cin >> n;
    int k; cin >> k;
    int a[n + 1]; for(int i = 1; i <= n; i++) cin >> a[i];
    multiset<int> data;
    for(int i = 1; i <= n; i++) data.insert(a[i]);
    multiset<int, greater<int>> ms;
    int curr = k;
    int cnt = 0;
    while(!data.empty()) {
        while(1) {
            auto it = data.upper_bound(curr);
            if(it == data.begin()) {
                if(!ms.empty()) {
                    int temp = *ms.begin();
                    ms.erase(ms.begin());
                    curr += temp;
                    cnt++;
                }
                else {
                    cout << "-1\n";
                    return ;
                }
            }
            else {
                it--;
                int val = *it;
                data.erase(it);
                ms.insert(2 * val);
                curr -= val;
                break;
            }
        }
    }
    cout << cnt << "\n";
    /*sort(a + 1, a + n + 1);
    multiset<int, greater<int>> ms;
    int temp = k;
    int cnt = 0;
    for(int i = 1; i <= n; i++) {
        int total = 0;
        while(temp < a[i] and !ms.empty()) {
            int temp1 = *ms.begin();
            ms.erase(ms.begin());
            temp += temp1;
            cnt++;
        }
        if(temp < a[i]) {
            cout << "-1\n";
            return ;
        }
        ms.insert(a[i] * 2);
        temp -= a[i];
    }*/
}
signed main() {
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);

    int t;
    cin >> t;
    while(t--) {
        solve();
    }
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 0
Wrong Answer
time: 250ms
memory: 14308kb

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:

4
2
2
3
-1
10621
4
-1
7
5385
8
2
-1
5
6264
3
0
-1
124835
5
-1
7
10940
1
3
100000
5
-1
-1

result:

wrong answer 19th lines differ - expected: '124764', found: '124835'