QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#840461#6886. Simple Set ProblemsurenjamtsAC ✓1025ms104712kbC++201.0kb2025-01-02 18:46:562025-01-02 18:47:05

Judging History

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

  • [2025-01-02 18:47:05]
  • 评测
  • 测评结果:AC
  • 用时:1025ms
  • 内存:104712kb
  • [2025-01-02 18:46:56]
  • 提交

answer

#include<bits/stdc++.h>
using namespace std;
using ll = long long;
#define pb push_back
#define eb emplace_back
#define all(x) (x).begin(),(x).end()
#define F first
#define S second


void solve(){
    int k;
    cin >> k;
    vector<vector<int>> sets(k);
    for(auto &st : sets){
        int n;
        cin >> n;
        st.assign(n, 0);
        for(auto &x : st) cin >> x;
        sort(all(st));
        reverse(all(st));
    }

    set<pair<int, int>> tops;
    for(int i = 0; i < k; i++){
        tops.insert({sets[i].back(), i});
    }
    ll ans = 1e18;
    while(true){
        auto [mn, i] = *tops.begin();
        auto [mx, _] = *prev(tops.end());
        ans = min(ans, (ll)mx - mn);
        sets[i].pop_back();
        tops.erase(tops.begin());
        if(sets[i].empty()) break;
        tops.insert({sets[i].back(), i});
    }
    cout << ans << '\n';
}
int32_t main(){
    ios::sync_with_stdio(0); cin.tie(NULL); cout.tie(NULL);
    int t; cin >> t; while(t--)
    solve();
    return 8/13;
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 100
Accepted
time: 1025ms
memory: 104712kb

input:

10018
1
5 -247462786 -97914904 849160785 -951926514 -829935728
7
72 8382969 -3251289 -63130380 -590108505 -798189380 -140833313 -626464256 136468139 -711222365 500861930 -459837972 914918723 186793042 872925162 -335485808 641571163 -314777234 -520573290 -894124702 618889116 2700292 -714868427 -34346...

output:

0
1800402714
860165806
487641037
229279918
238532335
392707612
456994871
256099628
1023121975
4986247
753213024
0
1289600751
598093746
55025093
95257568
145430738
34342513
0
157895624
789721360
232287715
1817496622
439049782
777966568
29118927
1671939338
1048279188
42073227
642353647
61747459
302989...

result:

ok 10018 lines