QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#259339#7750. Revenge on My BossPlentyOfPenalty#WA 74ms8344kbC++201.3kb2023-11-20 20:30:262023-11-20 20:30:27

Judging History

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

  • [2023-11-20 20:30:27]
  • 评测
  • 测评结果:WA
  • 用时:74ms
  • 内存:8344kb
  • [2023-11-20 20:30:26]
  • 提交

answer

#include<bits/stdc++.h>
#define all(x) begin(x),end(x)
using namespace std;
const int N=1e5+9;
int T,n,m,a[N],b[N],c[N],w[N];
vector<int> neg,pos,tot,ans;
long long l,r,mid,sa[N],sb[N],lim[N];
bool check(long long x){
	// cerr<<"! check >> "<<x<<endl;
	for(int i=1;i<=n;i++){
		lim[i]=x/c[i]-sb[1]+b[i];
	}
	sort(all(neg),[&](int i,int j){return lim[i]>lim[j];});
	sort(all(pos),[&](int i,int j){return lim[i]<lim[j];});
	long long sum=0;
	tot.clear();
	tot.insert(tot.end(),all(neg));
	tot.insert(tot.end(),all(pos));
	for(int x:tot){
		sum+=w[x];
		if(sum>lim[x])return false;
	}
	ans=tot;
	return true;
}
int main(){
#ifdef memset0
	freopen("E.in","r",stdin);
#endif
	cin.tie(0)->sync_with_stdio(0);
	cin>>T;
	while(T--){
		cin>>n;
		pos.clear();
		neg.clear();
		ans.clear();
		for(int i=1;i<=n;i++){
			cin>>a[i]>>b[i]>>c[i];
			w[i]=a[i]-b[i];
			if(w[i]>0){
				pos.push_back(i);
			}else{
				neg.push_back(i);
			}
		}
		sb[n+1]=0;
		for(int i=1;i<=n;i++)sa[i]=sa[i-1]+a[i];
		for(int i=n;i>=1;i--)sb[i]=sb[i+1]+b[i];
		l=r=0;
		for(int i=1;i<=n;i++){
			r=max(r,(long long)c[i]*(sa[i]+sb[i]));
		}
		// cerr<<"! "<<l<<" "<<r<<endl;
		while(l<=r){
			mid=(l+r)>>1;
			if(check(mid)){
				r=mid-1;
			}else{
				l=mid+1;
			}
		}
		assert(ans.size()==n);
		for(int i=0;i<n;i++)cout<<ans[i]<<" \n"[i+1==n];
	}
}

详细

Test #1:

score: 100
Accepted
time: 1ms
memory: 5472kb

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
3 8 4 2 5 9 7 1 6

result:

ok correct

Test #2:

score: -100
Wrong Answer
time: 74ms
memory: 8344kb

input:

1
100000
581297 102863 1
742857 42686 1
676710 233271 1
443055 491162 1
442056 28240 1
769277 331752 1
8608 369730 1
495112 525554 1
787449 938154 1
441186 850694 1
84267 925450 1
740811 32385 1
834021 37680 1
257878 564126 1
90618 914340 1
239641 463103 1
40687 343062 1
587737 458554 1
103684 48666...

output:

34165 58976 76404 97462 81944 63569 22053 24693 82043 7559 68501 35301 39883 11448 91985 42218 73062 38913 60104 61747 17135 39691 48773 76455 53224 928 82878 21243 40729 98834 2119 26666 44145 1844 67247 94650 78710 92428 758 81020 70922 1714 62638 25132 88997 54154 80672 33568 69608 44151 77582 44...

result:

wrong answer Wrong Answer on Case#1