QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#262894 | #7750. Revenge on My Boss | lureny | WA | 1ms | 3424kb | C++14 | 3.3kb | 2023-11-24 11:36:53 | 2023-11-24 11:36:53 |
Judging History
answer
#include <bits/stdc++.h>
using namespace std;
using ll=long long;
using LL=long long;
using ld=long double;
using pii=pair<int,int>;
using pll=pair<ll,ll>;
#define fi first
#define se second
#define V vector
#define pb push_back
#ifndef LOCAL
#define endl '\n'
#endif
const int N = 2e6;
const ll mod = 1e9+7;
ll pn[N];
bool vis[N];
ll ct[N];
ll tot[N][12];
string st;
int cnt = 0;
V<V<int>> ve;
void solve() {
ll n;
cin >> n;
V<ll> va(n+1);
V<ll> vb(n+1);
V<ll> vc(n+1);
V<pll> dif(n+1);
ll sumth1 = 0;
ll sumth2 = 0;
ll cnt1 = 0,cnt2 = 0;
for(int i = 1;i<=n;i++){
cin >> va[i] >> vb[i] >> vc[i];
dif[i].first = va[i]-vb[i];
dif[i].second = i;
sumth1 += va[i];
sumth2 += vb[i];
if(va[i]<=vb[i]) cnt1++;
}
sort(dif.begin()+1,dif.end());
ll l = 1,r = 1e18;
while(1){
ll mid = (l+r)/2;
bool flag = 1;
priority_queue<pll, V<pll>, greater<pll> > pt;
V<pll> st(cnt1+1);
for(int i = 1;i<=cnt1;i++){
int index = dif[i].second;
st[i].first = sumth2+va[index]-mid/vc[index];
st[i].second = i;
}
V<ll> ans1(cnt1+1);
ll tot = 0;
int nnt = 1;
sort(st.begin()+1,st.end());
for(int i = 1;i<=cnt1;i++){
while(nnt<=cnt1 && tot+st[nnt].first<=0){
pt.push({st[nnt].second, dif[st[nnt].second].first});
nnt++;
}
if(!pt.empty()){
auto it = pt.top();
pt.pop();
ans1[i] = dif[it.first].second;
tot += it.second;
}
else{
flag = 0;
break;
}
}
if(flag == 0){
l = mid+1;
continue;
}
// priority_queue<pll, V<pll>, greater<V<pll>>> pt2;
cnt2 = n-cnt1;
V<pll> st2(n-cnt1+1);
for(int i = 1;i<=cnt2;i++){
int index = dif[n-i+1].second;
st2[i].first = sumth1+vb[index]-mid/vc[index];
st2[i].second = i;
}
V<ll> ans2(cnt2+1);
tot = 0;
nnt = 1;
sort(st2.begin()+1,st2.end());
for(int i = 1;i<=cnt2;i++){
while(nnt<=cnt2 && tot+st2[nnt].first<=0){
pt.push({st2[nnt].second, dif[n-st2[nnt].second+1].first});
nnt++;
}
if(!pt.empty()){
auto it = pt.top();
pt.pop();
ans2[i] = dif[n-it.first+1].second;
tot -= it.second;
}
else{
flag = 0;
break;
}
}
if(flag == 0){
l = mid+1;
continue;
}
else r = mid;
if(l == r){
for(int i = 1;i<=cnt1;i++) cout << ans1[i] << ' ';
for(int i = cnt2;i;i--) cout << ans2[i] << ' ';
cout << '\n';
cout << l << '\n';
break;
}
}
}
int main() {
#ifdef LOCAL
ios::sync_with_stdio(false);
cin.tie(0);
cout.tie(0);
freopen("in.txt","r",stdin);
freopen("out.txt","w",stdout);
#endif
int t=1;
cin>>t;
while(t--)
solve();
return 0;
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 0
Wrong Answer
time: 1ms
memory: 3424kb
input:
2 4 1 1 4 5 1 5 1 9 1 9 8 1 9 3 1 4 1 5 9 2 6 5 3 5 8 9 7 9 3 2 3 8 4 6 2 6 8 3 2 7
output:
3 1 2 4 80 3 8 2 4 5 6 9 1 7 297
result:
wrong answer Integer parameter [name=pi] equals to 80, violates the range [1, 9]