QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#265432#7744. Elevatorucup-team1074WA 122ms8508kbC++202.2kb2023-11-25 18:24:042023-11-25 18:24:04

Judging History

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

  • [2023-11-25 18:24:04]
  • 评测
  • 测评结果:WA
  • 用时:122ms
  • 内存:8508kb
  • [2023-11-25 18:24:04]
  • 提交

answer

#include <bits/stdc++.h>
using namespace std;
#define LL long long
#define pb push_back
#define x first
#define y second 
#define endl '\n'
const LL maxn = 4e05+7;
const LL N = 1e05+10;
const LL mod = 1e09+7;
const int inf = 0x3f3f;
const LL llinf = 5e18;
typedef pair<int,int>pl;
priority_queue<LL , vector<LL>, greater<LL> >mi;//小根堆
priority_queue<LL> ma;//大根堆
LL gcd(LL a, LL b){
	return b > 0 ? gcd(b , a % b) : a;
}

LL lcm(LL a , LL b){
	return a / gcd(a , b) * b;
}
LL n , m;
LL a[N];
vector<vector<LL>>cnt_f(N , vector<LL>(2));
void init(int n){
	for(int i = 0 ; i <= n ; i ++){
		a[i] = 0 ,cnt_f[i][0] = cnt_f[i][1] = 0;
	}
}
void solve() 
{
	cin >> n >> m;	
	set<LL>num;
	set<LL>st[2];
	for(int i = 0 ; i < n ; i ++){
		LL x , y , z;
		cin >> x >> y >> z;
		num.insert(z);
		cnt_f[z][y - 1] += x;
		st[y - 1].insert(z);
	}
	vector<LL>f;
	for(auto it : num){
		f.pb(it);
	}
	auto cmp = [&](LL x , LL y){
		return x > y;
	};
	sort(f.begin() , f.end() , cmp);
	LL res = 0;
	LL len = f.size();
	for(LL i = 0 ; i < len ; ){
		LL eve = m;
		LL tt = f[i];
		while(i < len && eve >= cnt_f[f[i]][0] + cnt_f[f[i]][1] * 2){
			eve -= cnt_f[f[i]][0] + cnt_f[f[i]][1] * 2;
			st[0].erase(f[i]);
			st[1].erase(f[i]);
			cnt_f[f[i]][0] = 0;
			cnt_f[f[i]][1] = 0;
			i++;
		}
		if(i >= len){
			res += tt;
			break;
		}
		if(eve >= cnt_f[f[i]][1] * 2){
			eve -= cnt_f[f[i]][1] * 2;
			cnt_f[f[i]][1] = 0;
			st[1].erase(f[i]);
		}
		else{
			cnt_f[f[i]][1] -= eve / 2;
			eve = eve % 2 == 0 ? 0 : 1;
		}
		if(eve >= cnt_f[f[i]][0]){
			eve -= cnt_f[f[i]][0];
			cnt_f[f[i]][0] = 0;
			st[0].erase(f[i]);			
		}
		else{
			cnt_f[f[i]][0] -= eve;
			eve = 0;	
		}
		if(eve > 0){
			auto it = st[0].lower_bound(f[i]);
			if(it != st[0].begin()){
				it--;
				LL x = *it;
				cnt_f[x][0]--;
				if(cnt_f[x][0] == 0){
					st[0].erase(x);
				}
			}
		}
		res += tt;
	}
	cout << res << endl;
}            
int main() 
{
    ios::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
    cout.precision(10);
    int t=1;
	cin>>t;
	if(t != 2){
		t--;
	}
    while(t--)
    {
    	solve();
    }
    return 0;
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 100
Accepted
time: 4ms
memory: 8508kb

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: 122ms
memory: 8464kb

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
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 5501st lines differ - expected: '1000000000000000', found: ''