QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#276571#7744. ElevatorVegetable_DogWA 101ms5876kbC++141.6kb2023-12-05 22:57:572023-12-05 22:57:57

Judging History

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

  • [2023-12-05 22:57:57]
  • 评测
  • 测评结果:WA
  • 用时:101ms
  • 内存:5876kb
  • [2023-12-05 22:57:57]
  • 提交

answer

#include<bits/stdc++.h>
const int N = 100005;
using namespace std;

struct bags{
	long long c, w, f;
	bool operator <(const bags &o)const{
		return f>o.f;
	}
}bag[N];

int n;
long long k;

void real_main(){
	cin>>n>>k;
	for(int i=1;i<=n;i++){
		cin >> bag[i].c >> bag[i].w >> bag[i].f;
	}
	sort(bag+1, bag+1+n);
	
	long long ans = 0 ;
	
	long long now = 1;            // 现在处理到第几组包裹
	queue<int> q;
	
	for(int i=1;i<=n;i++){
		if(bag[i].w == 1){
			q.push(i);
		}
	}
	
	while(now<=n) {
		
		if(bag[now].c * bag[now].w >= k){  // 全部处理当前组 
			long long times = bag[now].c * bag[now].w / k;  // 完整处理几次
			ans += times * bag[now].f; 
			bag[now].c -= times * k / bag[now].w;
			while (bag[now].c == 0 && now <= n){
				now++;
			} 
		} else {  // 当前组只占部分空间便处理完成 剩余空间分给后面的组 
			ans += bag[now].f;
			long long now_k = k - bag[now].c * bag[now].w;
			now++;
			while(now_k - bag[now].c * bag[now].w >= 0 && now <= n){  // 能整组吃掉 
				now_k -= bag[now].c * bag[now].w;
				now ++;
			}
			
			if(now>n) break;
			
			if(now_k%2==1){
				while(q.size()&&q.front()<now) q.pop();
				while(q.size()&&bag[q.front()].c <= now_k){  // 整组吃掉 w = 1 的 
					bag[q.front()].c = 0;
					now_k -= bag[q.front()].c;
					q.pop();
				}	
				if(q.size()){
					bag[q.front()].c -= now_k;
				}
			} else {
				bag[now].c -= now_k / bag[now].w;
			}
		}
		
	}
	cout<<ans<<endl; 
}

int main(){
	int T;
	for(cin>>T;T;T--){
		real_main();
	}
	return 0;
}

詳細信息

Test #1:

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

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: 101ms
memory: 5876kb

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
23
4
5
7
1
3
9
6
1
10
4
9
23
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
19
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 15th lines differ - expected: '17', found: '23'