QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#635738#7744. ElevatorhansueTL 1ms5388kbC++141.8kb2024-10-12 20:48:322024-10-12 20:48:37

Judging History

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

  • [2024-10-12 20:48:37]
  • 评测
  • 测评结果:TL
  • 用时:1ms
  • 内存:5388kb
  • [2024-10-12 20:48:32]
  • 提交

answer

#include<iostream>
#include<cstdio>
#include<cstring>
#include<cmath>
#include<algorithm>
using namespace std;

typedef long long LL;
const int N = 1e5;

	int n;
	LL k;
	LL a[N + 3][2];				//floor i; even, odd
	int m, b[N + 3];
	
void next(int &f){
	int i = lower_bound(b + 1, b + m + 1, f) - b - 1;
	if(i == m)
		f = 0;
	else 
		f = b[i + 1];
}

void sol(){
	scanf("%d%lld", &n, &k);
	
	memset(a, 0, sizeof a);
	m = 0;
	for(int i = 1, c, w, f; i <= n; i++){
		scanf("%d%d%d", &c, &w, &f);
		a[f][w & 1] += c;
		b[++m] = f;
	}
	
	sort(b + 1, b + m + 1, greater<int>());
	m = unique(b + 1, b + m + 1) - b - 1;
		
	int oddpos = 1;
	LL ans = 0;
	for(int i = 1; i <= m;){
		while(i <= m && a[b[i]][0] == 0 && a[b[i]][1] == 0)
			i++;
		if(i == m + 1)
			break;
		
		LL tmp = 0;
		int cost = b[i];
		while(i <= m && (tmp + 2 * a[b[i]][0] + a[b[i]][1] <= k)){
			tmp += 2 * a[b[i]][0] + a[b[i]][1];
			i++;
		}
		if(i == m + 1){
			ans += cost;
			break;
		}
		if(tmp == k){
			ans += cost;
			continue;
		}
		
		if(tmp + 2 * a[b[i]][0] > k){
			a[b[i]][0] -= (k - tmp) / 2;
			if(tmp & 1){
				if(a[b[i]][1] > 0)
					a[b[i]][1]--;
				else {
					while(oddpos <= i || (oddpos <= m && a[oddpos][0] == 0))
						oddpos++;
					if(oddpos <= m){
						a[oddpos][1]--;
					}
				}
			}
			ans += cost;
			
			if(2 * a[b[i]][0] >= k){
				LL div = 2 * a[b[i]][0] / k;
				ans += b[i] * div;
				a[b[i]][0] -= div * k / 2;
			}
			
			continue;
		}
		
		tmp += 2 * a[b[i]][1];
		a[b[i]][1] -= k - tmp;
		ans += cost;
		
		if(a[b[i]][1] >= k){
			LL div = a[b[i]][1] / k;
			ans += b[i] * div;
			a[b[i]][1] -= div * k;
		}
		
	}
	
	printf("%lld\n", ans);
	
}

int main(){
	int T;
	scanf("%d", &T);
	while(T--)
		sol();

	return 0;

}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

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

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
Time Limit Exceeded

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:


result: