QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#635941#7744. ElevatorYurilyWA 17ms5988kbC++201.5kb2024-10-12 21:32:442024-10-12 21:32:45

Judging History

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

  • [2024-10-12 21:32:45]
  • 评测
  • 测评结果:WA
  • 用时:17ms
  • 内存:5988kb
  • [2024-10-12 21:32:44]
  • 提交

answer

#include<bits/stdc++.h>
using namespace std;
const int MAX=1e5+5;
int T;
struct node{
	long long h,num,w;
};
node c[MAX];
int n,p;
long long k;
void findodd(){
	while(p<=n&&!(c[p].w==1&&c[p].num))
		p++;
}
// 快读 
long long read(){
	long long x = 0, f = 1;
	char c = getchar();
	while(c < '0' || c > '9'){
		if(c == '-'){
			f = -1;
		}
		c = getchar();
	}
	while(c >= '0' && c <= '9'){
		x = x*10+c-'0';
		c = getchar();
	}
	return x*f;
}
bool cmp(node x,node y){
	return x.h>y.h;
}
void solve(){
	n=read(),k=read();
	for(int i=1;i<=n;++i){
		c[i].num=read(),c[i].w=read(),c[i].h=read();
	}
	sort(c+1,c+1+n,cmp);
	
	int cur=0;
	p=1;
	long long ans=0;
	while(cur<n){
		if(c[cur+1].num==0){
			cur++;
			continue;
		}
		
		long long sum=0;
		if(c[cur+1].num*c[cur+1].w<=k){
			ans+=c[cur+1].h;
			long long sum=0;
			while(cur<n&&sum+c[cur+1].num*c[cur+1].w<=k){
				sum+=c[cur+1].num*c[cur+1].w;
				c[cur+1].num=0;
				cur++;
			}
		//	cout<<cur<<endl;
			long long t=k-sum;
			if(cur<n){
				long long cnt=t/c[cur+1].w;
				c[cur+1].num-=cnt;
				if(sum<k){
					findodd();
					if(p!=n+1){
						c[p].num--;
					}
				}
			}
		}
		else{
			long long t=c[cur+1].num*c[cur+1].w/k;
			ans+=c[cur+1].h*t;
			c[cur+1].num-=t*k/c[cur+1].w;
		}		
	}
	
	if(c[n].num){
		long long t=c[n].num*c[n].w/k;
		if(c[n].num*c[n].w%k)
			t++;
		ans+=t*c[n].h; 
	}
	cout<<ans<<endl;
}
int main(){
	cin>>T;
	while(T--){
		solve();
	}
} 

Details

Tip: Click on the bar to expand more detailed information

Test #1:

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

input:

2
4 6
1 1 8
7 2 5
1 1 7
3 2 6
8 1200000
100000 1 100000
100000 1 12345
100000 2 100000
100000 2 12345
100000 1 100000
100000 1 12345
100000 2 100000
100000 2 12345

output:

24
100000

result:

ok 2 lines

Test #2:

score: -100
Wrong Answer
time: 17ms
memory: 5988kb

input:

5501
8 104
5 2 3
6 2 4
5 2 3
6 2 9
8 2 4
2 1 3
7 2 4
8 2 8
1 290
3 1 1
12 12
6 1 2
1 2 2
1 1 2
1 2 4
6 1 1
1 2 5
6 1 4
4 1 4
6 2 4
6 2 5
4 2 5
4 1 4
5 334
1 1 4
1 2 3
4 2 1
5 1 1
2 1 2
13 218
5 2 3
5 1 4
1 2 1
1 2 5
3 2 2
1 1 3
4 2 2
1 2 5
2 2 1
2 1 5
3 2 1
5 2 1
1 1 4
10 260
7 2 1
5 1 1
5 2 4
6 1 6...

output:

9
1
21
4
5
7
1
3
9
6
1
10
4
9
17
6
4
1
8
5
5
7
1
3
23
6
3
3
2
2
2
3
8
1
5
6
9
11
147
7
10
2
7
7
8
6
5
5
1
7
3
5
10
7
7
10
8
1
4
2
3
9
1
5
2
9
1
6
7
7
6
10
18
8
10
4
10
9
2
8
3
5
9
3
6
5
3
2
6
1
3
2
2
1
6
9
6
3
4
8
9
9
2
6
1
2
6
7
5
2
5
21
8
1
2
3
4
9
3
4
6
5
9
6
1
7
3
7
3
2
2
8
7
3
5
9
7
10
7
3
2
4
...

result:

wrong answer 3rd lines differ - expected: '23', found: '21'