QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#479178#7750. Revenge on My Bossucup-team052#WA 0ms3796kbC++141.8kb2024-07-15 15:42:082024-07-15 15:42:08

Judging History

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

  • [2024-07-15 15:42:08]
  • 评测
  • 测评结果:WA
  • 用时:0ms
  • 内存:3796kb
  • [2024-07-15 15:42:08]
  • 提交

answer

#include <bits/stdc++.h>
using namespace std;

#define N 100005
#define int long long
int read()
{
	int x; scanf("%lld",&x);
	return x;
}
struct Node
{
	int a,b,c,id;
};
vector<Node> a,b,c;
int n,sm;
int p[N];
struct Lim
{
	int v,w,id;
	Lim(int a=0,int b=0,int c=0) {v=a,w=b,id=c;}
};
bool cmp(Lim a,Lim b)
{
	return min(a.w,b.w-a.v)>min(b.w,a.w-b.v);
}
int chk(int mid)
{
	int cnt=0;
	{ // check a
		vector<Lim> l;
		for(int i=0;i<(int)a.size();i++)
		{
			int cango=mid/a[i].c-sm-a[i].b;
			l.emplace_back(a[i].b-a[i].a,cango,a[i].id);
		}
		sort(l.begin(),l.end(),cmp);
		int cur=0;
		for(int i=0;i<(int)l.size();i++)
		{
			if(cur>l[i].w) return 0;
			cur+=l[i].v;
			p[++cnt]=l[i].id;
		}
		reverse(p+1,p+cnt+1);
	}
	for(int i=0;i<(int)b.size();i++)
	{
		int tw=(sm+b[i].a)*b[i].c;
		p[++cnt]=b[i].id;
		if(tw>mid) return 0;
	}
	{ // check c
		vector<Lim> l;
		for(int i=0;i<(int)c.size();i++)
		{
			int cango=mid/c[i].c-sm-c[i].a;
			l.emplace_back(c[i].a-c[i].b,cango,c[i].id);
		}
		sort(l.begin(),l.end(),cmp);
		int cur=0;
		for(int i=0;i<(int)l.size();i++)
		{
			if(cur>l[i].w) return 0;
			cur+=l[i].v;
			p[++cnt]=l[i].id;
		}
	}
	return 1;
}
void work()
{
	n=read();
	a.clear(),b.clear(),c.clear();
	for(int i=1;i<=n;i++)
	{
		Node v;
		v.a=read(),v.b=read(),v.c=read();
		v.id=i;
		sm+=min(v.a,v.b);
		if(v.a<v.b) a.push_back(v);
		else if(v.a==v.b) b.push_back(v);
		else c.push_back(v);
	}
	int l=1,r=1e18,ans=0;
	while(l<=r)
	{
		int mid=(l+r)/2;
		if(chk(mid)) ans=mid,r=mid-1;
		else l=mid+1;
	}
	cout<<ans<<endl;
	chk(ans);
	for(int i=1;i<=n;i++) printf("%lld%c",p[i]," \n"[i==n]);
}
signed main() {
#ifdef xay5421
	freopen("a.in","r",stdin);
#endif
	int T; cin>>T; while(T--) work();
	return 0;
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 0
Wrong Answer
time: 0ms
memory: 3796kb

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:

80
3 1 2 4
396
3 8 4 2 5 9 7 1 6

result:

wrong answer Integer parameter [name=pi] equals to 80, violates the range [1, 4]