QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#695479 | #6693. Fast and Fat | iscreamc3 | TL | 1ms | 3556kb | C++17 | 1.6kb | 2024-10-31 20:07:22 | 2024-10-31 20:07:41 |
Judging History
answer
#include <bits/stdc++.h>
using namespace std;
using i64 = long long;
using u64 = unsigned long long;
#define Z cout << "\n"
#define lb lower_bound
#define ub upper_bound
#define inf 0x3f3f3f3f
#define INF 0x3f3f3f3f3f3f3f3f
#define unq(x) sort(x.begin(), x.end()), x.erase(unique(x.begin(), x.end()), x.end())
#define D(x) cerr << #x << ": " << (x) << "\n"
#define DV(v) cerr<< #v << ": "; for(int i=0;i <(v).size(); i++)cerr << ((v)[i]) << ",";cerr << "\n"
#if 0
#define int i64
#endif
struct node {
int v, w, no;
bool operator <(const node& o)const {
return v + w <= o.v + o.w;
}
bool operator >(const node& o)const {
return v + w > o.v + o.w;
}
};
void solve() {
int n;
cin >> n;
vector<node>a(n + 1);
set<node, greater<node>>se;
set<pair<int, int>>S;
for (int i = 1; i <= n; i++) {
cin >> a[i].v >> a[i].w;
a[i].no = i;
se.insert(a[i]);
S.insert({ a[i].v,i });
}
while (1) {
auto B = *S.begin();
auto top = *se.begin();
int yv = top.v;
int v = top.w + top.v - a[B.second].w;
v = min(v, yv);
//D(v);
se.erase(se.begin());
if (v < 0)break;
se.insert({ v,top.w,top.no });
se.erase({ B.first,a[B.second].w,B.second });
S.erase(S.begin());
S.erase({ top.v,top.no });
S.insert({ v, top.no });
}
cout << S.begin()->first << "\n";
}
signed main() {
cin.tie(0)->sync_with_stdio(false);
int t;
cin >> t;
while (t--)solve();
return 0;
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 1ms
memory: 3556kb
input:
2 5 10 5 1 102 10 100 7 4 9 50 2 1 100 10 1
output:
8 1
result:
ok 2 number(s): "8 1"
Test #2:
score: -100
Time Limit Exceeded
input:
10000 4 280251502 664541723 375808746 641141991 95134537 898607509 455259328 944978891 2 798417052 547329847 785434740 991778535 6 623628702 857611223 275667427 453747403 292209526 283132767 330752033 988721243 470297536 608192332 477186035 325224271 3 280572174 994054447 306566740 923535026 3781360...