QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#534317 | #1172. Junkyeom's Contest | 36champ | TL | 1ms | 3556kb | C++20 | 1.2kb | 2024-08-27 01:52:59 | 2024-08-27 01:52:59 |
Judging History
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, i;
for(i=n-1; i>=6; i--)
{
if(a[i] < a[i-1] + a[i-2] && a[i-1] + a[i-2] < a[i-3] + a[i-4] + a[i-5] + a[i-6])
{
ans = a[i] + a[i-1] + a[i-2] + a[i-3] + a[i-4] + a[i-5] + a[i-6];
break;
}
}
if(i >= 6)
{
for(int j=n-1; j>=0; j--)
{
int tl = a[j] - a[i - 2], tr = a[i - 3] + a[i - 4] + a[i - 5] + a[i - 6] - a[i - 2];
if(tr - tl < 2) continue;
int l = i - 1, r = j - 1;
while(l != r)
{
int m = (l + r + 1) / 2;
if(a[m] >= tr) r = m - 1;
else l = m;
}
if(a[l] > tl)
{
ans = max(ans, a[j] + a[l] + a[i - 2] + a[i - 3] + a[i - 4] + a[i - 5] + a[i - 6]);
}
}
}
cout << ans;
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 1ms
memory: 3556kb
input:
7 1 2 3 4 5 6 7
output:
-1
result:
ok 1 number(s): "-1"
Test #2:
score: -100
Time Limit Exceeded
input:
8 1 2 3 4 5 6 7 8