6 条题解

  • 1
    @ 2024-11-23 15:21:56

    标题

    你说得对,但是我AC了

    思路

    找到右最长和左最长的最后合并就可以了

    解题方法

    模拟

    Code

    #include <bits/stdc++.h>
    #define ll long long
    using namespace std;
    ll n, maxx1 = -1, maxx2 = -1, s1, d1, i, ans;
    
    struct lin {
    	int a, b;
    } arr[100010];
    
    int main() {
    	cin >> n;
    	for (i = 1; i <= n; i++) {
    		cin >> arr[i].a >> arr[i].b;
    		if (arr[i].a > ans) {
    			ans = arr[i].a;
    		}
    		//ans = max(ans, arr[i].a);
    		ll line1 = arr[i].a - arr[i].b, line2 = arr[i].b;
    		if (maxx1 < line1) {
    			s1 = i, d1 = 1;
    			maxx1 = line1;
    		}
    		if (maxx1 < line2) {
    			s1 = i, d1 = 2;
    			maxx1 = line2;
    		}
    	}
    	for (i = 1; i <= n; i++) {
    		ll line1 = arr[i].a - arr[i].b, line2 = arr[i].b;
    		if (maxx2 < line1) {
    			if (s1 == i && d1 == 1)
    				continue;
    			maxx2 = line1;
    		}
    		if (maxx2 < line2) {
    			if (s1 == i && d1 == 2)
    				continue;
    			maxx2 = line2;
    		}
    	}
    	cout << max(maxx1 + maxx2, ans) << endl;
    	return 0;
    }
    

    信息

    ID
    81
    时间
    3000ms
    内存
    512MiB
    难度
    2
    标签
    递交数
    1027
    已通过
    251
    上传者