QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#521908#6693. Fast and Fatzzisjtu#WA 58ms3900kbC++232.0kb2024-08-16 16:35:282024-08-16 16:35:29

Judging History

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

  • [2024-08-16 16:35:29]
  • 评测
  • 测评结果:WA
  • 用时:58ms
  • 内存:3900kb
  • [2024-08-16 16:35:28]
  • 提交

answer

#include <bits/stdc++.h>
#define ll long long
#define all(x) x.begin(), x.end()
#define lowbit(i) ((i)&(-i))
#define pii pair<int,int>
#define endl '\n'
#define mk(x,y) make_pair(x,y)
#define popcount(x) __builtin_popcount(x)
#define LF(x) fixed<<setprecision(x)
const double pi = 3.14159265358979323846;
const double eps = 1e-9;
const int inf = 1e9;
const long long INF = 4e18;
const int mod = 1e9+7;
using namespace std;
const int N = 1e5+10;

void solve() {
    int n;
    cin >> n;
    vector<int> a(n + 1), b(n + 1), id(n + 1);
    for(int i = 1; i <= n; i++) {
    	cin >> a[i] >> b[i];
    	id[i] = i;
    }
    sort(id.begin() + 1, id.end(), [&](int i, int j){
    	if(a[i] + b[i] == a[j] + b[j])return b[i] > b[j];
    	return a[i] + b[i] > a[j] + b[j];
    });
    // // for(int i = 1; i <= n; i++) {
    // // 	cout << a[id[i]] << " \n"[i == n];
    // // }
    int l = 1, r = inf;
    auto check = [&](int x) {
    	vector<array<int,2>>pos;
    	vector<array<int,2>>g;
    	for(int i = 1; i <= n; i++) {
    		if(a[id[i]] < x) {
    			pos.push_back({a[id[i]], b[id[i]]});
    		}
    		else g.push_back({a[id[i]], b[id[i]]});
    	}
    	if(pos.size() == 0)return true;
    	if(pos.size() > g.size())return false;
    	vector<int> vis(n + 1);
    	for(auto[v, w]: pos) {
    		bool flag = 1;
    		for(int i = 0; i < g.size(); i++) {
    			if(vis[i])continue;
    			int v_ = g[i][0];
    			int w_ = g[i][1];
    			if(w_ >= w) {
    				vis[i] = 1;
    				flag = false;
    				break;
    			}
    			else {
    				if(v_ - (w - w_) >= x) {
    					vis[i] = 1;
    					flag = false;
    					break;
    				}
    			}
    		}
    		if(flag)return false;
    	}
    	return true;
    };
    while(l < r) {
    	int mid = (l + r + 1) >> 1;
    	if(check(mid))l = mid;
    	else r = mid - 1;
    }
    cout << l << endl;
}

int main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
    
    int T = 1;
    cin >> T;
    while (T--) {
        solve();
    }
    return 0;
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

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

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: 58ms
memory: 3900kb

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
470297536
280572174
620790284
960871619
691253609
525403368
136979645
399988835
551368832
576427565
581083992
315900406
370430730
526259135
781258283
631916852
300930080
419192366
431930706
467117534
530080165
391912906
707870587
461145922
457987604
389750718
447390353
696516804
...

result:

wrong answer 5th numbers differ - expected: '704877362', found: '620790284'