Run ID 作者 问题 语言 测评结果 分数 时间 内存 代码长度 提交时间
36093 沈仲恩 【S】T2 C++ 通过 100 1820 MS 448 KB 1102 2025-02-07 15:38:06

Tests(20/20):


#include <bits/stdc++.h> using namespace std; int a[10005], n; signed main() { ios::sync_with_stdio(false); cin.tie(0); cin >> n; for (int i = 1; i <= n; i++) { cin >> a[i]; } long long ans = 0; for (int i = 1; i <= n; i++) { priority_queue <int> dq; priority_queue <int, vector <int>, greater <int> > xq; for (int j = i; j <= n; j++) { if (j == i) dq.push(a[j]); else if (dq.top() >= a[j]) dq.push(a[j]); else xq.push(a[j]); if (((j - i) & 1) == 0) { while (dq.size() - 1 > xq.size()) { xq.push(dq.top()); dq.pop(); } while (xq.size() > dq.size()) { dq.push(xq.top()); xq.pop(); } ans += 1ll * i * j * dq.top(); } } } printf("%lld", ans); return 0; }


测评信息: