QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#671956#6693. Fast and FatSchoolbagWA 56ms3756kbC++201.8kb2024-10-24 15:07:472024-10-24 15:07:47

Judging History

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

  • [2024-10-24 15:07:47]
  • 评测
  • 测评结果:WA
  • 用时:56ms
  • 内存:3756kb
  • [2024-10-24 15:07:47]
  • 提交

answer

#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef map<int, int> mii;
typedef unordered_map<int, int> umii;
typedef pair<int, int> pii;
typedef pair<long long, long long> pll;
typedef vector<int> vi;
typedef vector<vector<int>> vc;
typedef vector<long long> vl;
typedef vector<vector<long long>> vll;
typedef __int128_t int128;
#define rep(x, y, z) for(int x = (y); x <= (z); x++)
#define per(x, y ,z) for(int x = (y); x >= (z); x--)
#define yes cout << "YES\n"
#define no cout << "NO\n"

//#define int long long
//const int N = 1e5 + 5;
//const int mod = 1e9 + 7;
const ll inf = 1e10;

void solve(){
	int n; cin >> n;
	vector<pll> a(n + 1, {-1, -1}), b(n + 1, {-1, -1});
	ll l = inf, r = -inf; 
	rep(i, 1, n){
		cin >> a[i].first >> a[i].second; // v, w
		b[i] = a[i];
		l = min(l, a[i].first);
		r = max(r, a[i].first);
	}
	sort(a.begin() + 1, a.end(), [&](pll x, pll y){
		return x.first + x.second > y.first + y.second;
	});
	sort(b.begin() + 1, b.end(), [&](pll x, pll y){
		return x.second > y.second;
	});
	auto check = [&](ll tar) -> bool{
		vl p, q;
		rep(i, 1, n){
			if(a[i].first >= tar){
				p.push_back(a[i].first + a[i].second - tar);
			}
			if(b[i].first < tar){
				q.push_back(b[i].second);
			}
		}
		if(p.size() < q.size()) return 0;
		rep(i, 0, (int)q.size() - 1){
			if(p[i] < q[i]) return 0;
		}
		return 1;
	};
	ll ans = l;
	while(l < r){ // 找符合条件的最大值
		ll mid = (l + r + 1) / 2; // ac
		// ll mid = (l + r) / 2;     tle
		if(check(mid)) l = mid + 1, ans = mid;
		else r = mid - 1;
	}
	cout << ans << '\n';
}

signed main(){
	std::ios::sync_with_stdio(false);
	std::cin.tie(nullptr);

	int __ = 1; cin >> __;
	while(__--){
		solve();
	}
	return 0;
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 100
Accepted
time: 0ms
memory: 3756kb

input:

2
5
10 5
1 102
10 100
7 4
9 50
2
1 100
10 1

output:

8
1

result:

ok 2 number(s): "8 1"

Test #2:

score: -100
Wrong Answer
time: 56ms
memory: 3604kb

input:

10000
4
280251502 664541723
375808746 641141991
95134537 898607509
455259328 944978891
2
798417052 547329847
785434740 991778535
6
623628702 857611223
275667427 453747403
292209526 283132767
330752033 988721243
470297536 608192332
477186035 325224271
3
280572174 994054447
306566740 923535026
3781360...

output:

352409014
785434740
470297535
280572173
704877361
960871618
691253609
560579095
136979645
399988834
610497257
576427565
636500913
315900406
370430730
526259134
781258283
631916852
300930079
419999540
431930705
479323438
530080165
391912906
708925499
467782811
457987604
389750717
447390352
696516804
...

result:

wrong answer 3rd numbers differ - expected: '470297536', found: '470297535'