QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#179049 | #6886. Simple Set Problem | PPP# | AC ✓ | 1361ms | 128556kb | C++17 | 1.1kb | 2023-09-14 17:11:24 | 2023-09-14 17:11:26 |
Judging History
answer
#ifdef DEBUG
#define _GLIBCXX_DEBUG
#endif
//#pragma GCC optimize("O3")
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
int k;
void solve() {
cin >> k;
vector<vector<ll>> a(k);
vector<pair<ll,int>> t;
for (int i = 0; i < k; i++) {
int sz;
cin >> sz;
a[i].resize(sz);
for (ll& u : a[i]) {
cin >> u;
t.emplace_back(u, i);
}
}
sort(t.begin(), t.end());
vector<ll> mn(k);
multiset<ll> vals;
for (int i = 0; i < k; i++) {
mn[i] = 1e18;
vals.insert(mn[i]);
}
ll best = 1e18;
reverse(t.begin(), t.end());
for (auto& it : t) {
int id = it.second;
vals.erase(vals.find(mn[id]));
mn[id] = it.first;
vals.insert(mn[id]);
best = min(best, *(--vals.end()) - mn[id]);
}
cout << best << '\n';
}
int main() {
ios_base::sync_with_stdio(false);
cin.tie(nullptr);
#ifdef DEBUG
freopen("input.txt", "r", stdin);
#endif
int tst;
cin >> tst;
while (tst--) {
solve();
}
return 0;
}
详细
Test #1:
score: 100
Accepted
time: 1361ms
memory: 128556kb
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