QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#672868#664. TriangleUrdWA 0ms3692kbC++171.2kb2024-10-24 19:35:482024-10-24 19:35:48

Judging History

This is the latest submission verdict.

  • [2024-10-24 19:35:48]
  • Judged
  • Verdict: WA
  • Time: 0ms
  • Memory: 3692kb
  • [2024-10-24 19:35:48]
  • Submitted

answer

#include <bits/stdc++.h>
#define ALL(v) begin(v), end(v)

using i64 = int64_t;

const int kMaxN = 1E5 + 5;

int n, p;
std::array<i64, kMaxN> a;
i64 ans;
void Eval(int u, int v, int w) {
  if (a[u] >= a[v] + a[w]) return;
  auto Next = [&](int x) {
    ++x;
    while (x == u || x == v || x == w) ++x;
    return x;
  };
  i64 s = a[u] + a[v] + a[w];
  for (int i = p; i + 2 < n; ++i) {
    int j = Next(i), k = Next(j);
    if (j == n || k == n) continue;
    if (a[i] < a[j] + a[k]) {
      ans = std::max(ans, a[i] + a[j] + a[k] + s);
      return;
    }
  }
}

auto main() -> int {
  std::ios::sync_with_stdio(false);
  std::cin.tie(nullptr), std::cout.tie(nullptr);

  std::cin >> n;
  for (int i = 0; i < n; ++i) std::cin >> a[i];
  std::sort(a.data(), a.data() + n, std::greater());
  for (p = 0; p + 2 < n; ++p) {
    if (a[p] < a[p + 1] + a[p + 2]) break;
  }
  for (int i = 0; i + 2 < n; ++i) {
    Eval(i, i + 1, i + 2);
    if (i + 3 < n) Eval(i, i + 1, i + 3);
    if (i + 4 < n) Eval(i, i + 1, i + 4);
    if (i + 3 < n) Eval(i, i + 2, i + 3);
    if (i + 4 < n) Eval(i, i + 2, i + 4);
    if (i + 4 < n) Eval(i, i + 3, i + 4);
  }
  std::cout << ans << '\n';

  return 0;
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

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

input:

100
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1

output:

6

result:

ok single line: '6'

Test #2:

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

input:

100
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
2
1
1
1
1
1
1
1
1

output:

6

result:

ok single line: '6'

Test #3:

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

input:

100
1
1
1
1
1
1
1
1
1
1
1
1
1
2
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
2
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1

output:

8

result:

ok single line: '8'

Test #4:

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

input:

100
2
2
2
1
2
1
1
1
1
1
2
2
1
1
1
1
1
1
1
2
2
1
1
1
2
2
2
2
1
1
2
2
1
2
1
1
1
2
1
2
2
2
2
2
2
2
1
2
1
1
2
1
2
1
1
2
1
1
2
1
2
2
2
1
2
1
2
1
2
2
2
1
1
2
1
2
2
2
1
2
1
1
1
2
1
2
1
2
2
2
1
1
2
2
2
1
1
2
1
1

output:

12

result:

ok single line: '12'

Test #5:

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

input:

100
2
1
1
2
1
2
1
2
2
1
1
2
2
2
1
1
2
1
2
1
2
2
2
1
2
1
2
1
2
1
1
2
2
2
2
2
1
2
1
2
2
1
2
2
1
1
1
1
2
2
1
2
2
2
1
2
2
1
1
3
1
2
2
1
1
1
2
1
2
2
1
1
1
2
1
1
2
1
1
2
2
1
1
2
1
1
1
2
1
2
1
1
1
2
1
1
2
2
2
1

output:

14

result:

wrong answer 1st lines differ - expected: '13', found: '14'