QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#534304#1172. Junkyeom's Contest36champWA 0ms3816kbC++201.1kb2024-08-27 01:30:052024-08-27 01:30:05

Judging History

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

  • [2024-08-27 01:30:05]
  • 评测
  • 测评结果:WA
  • 用时:0ms
  • 内存:3816kb
  • [2024-08-27 01:30:05]
  • 提交

answer

#include <bits/stdc++.h>
#define ll long long
#define pb push_back

using namespace std;

int main()
{
    ios_base::sync_with_stdio(false);
	cin.tie(nullptr);
	cout.tie(nullptr);

	int n;
	cin >> n;

	vector<int> a(n);
	for(int i=0; i<n; i++) cin >> a[i];
	sort(a.begin(), a.end());

	int ans = -1;
	for(int i = n - 1; i >= 6; i--)
    {
        int l1 = i - 1, r1 = n - 2, target = a[i - 3] + a[i - 4] + a[i - 5] + a[i - 6] - a[i - 2];
        while(l1 != r1)
        {
            int m = (l1 + r1 + 1) / 2;

            if(a[m] >= target) r1 = m - 1;
            else l1 = m;
        }

        if(a[l1] + a[i-2] >= a[i-3] + a[i-4] + a[i-5] + a[i-6]) continue;

        int l0 = l1 + 1, r0 = n - 1;
        target = a[i-2] + a[l1];
        while(l0 != r0)
        {
            int m = (l0 + r0 + 1) / 2;

            if(a[m] >= target) r0 = m - 1;
            else l0 = m;
        }

        if(a[l0] >= a[l1] + a[i-2]) continue;

        //cout << "! " << l0 << " " << l1 << " " << i - 2 << "\n";
        ans = a[l0] + a[l1] + a[i-2] + a[i-3] + a[i-4] + a[i-5] + a[i-6];
        break;
    }

    cout << ans;
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

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

input:

7
1 2 3 4 5 6 7

output:

-1

result:

ok 1 number(s): "-1"

Test #2:

score: 0
Accepted
time: 0ms
memory: 3580kb

input:

8
1 2 3 4 5 6 7 8

output:

35

result:

ok 1 number(s): "35"

Test #3:

score: -100
Wrong Answer
time: 0ms
memory: 3816kb

input:

10
5 5 5 5 5 5 10 5 5 5

output:

-1

result:

wrong answer 1st numbers differ - expected: '35', found: '-1'