提交记录 8535
提交时间 |
评测时间 |
2019-02-23 18:53:28 |
2020-08-01 01:20:33 |
// luogu-judger-enable-o2
#include <iostream>
#include <cstdio>
#include <cstring>
#include <algorithm>
#include <cmath>
#include <queue>
#include <vector>
using namespace std;
int d[100100], n;
long long ans;
priority_queue <int, vector<int>, greater<int> > q;
inline int read()
{
int x = 0;
char ch = getchar();
while (ch < '0' || ch > '9')
ch = getchar();
while (ch >= '0' && ch <= '9')
x = x * 10 + ch - '0', ch = getchar();
return x;
}
int main()
{
// freopen("road.in", "r", stdin);
// freopen("road.out", "w", stdout);
scanf("%d", &n);
for (int i = 1; i <= n; i++)
d[i] = read();
while(1)
{
bool flag = 1;
int last = 1;
for (int i = 1; i <= n + 1; i++)
{
if (d[i] == 0 && d[i - 1] == 0 && d[i + 1] == 0)
{
last = i + 1;
continue;
}
if (d[i] != 0 && (d[i - 1] == 0 && d[i + 1] == 0))
{
ans += d[i];
d[i] = 0;
last = i + 1;
continue;
}
if (d[i] != 0) flag = 0, q.push(d[i]);
if (d[i] == 0 && last != i)
{
int del = q.top();
ans += del;
for (int j = last; j <= i; j++)
if (d[j])
d[j] -= del;
last = i + 1;
while(!q.empty())
q.pop();
}
}
if (flag)
break;
}
printf("%lld", ans);
return 0;
}//6 4 3 2 5 3 5
Compilation | N/A | N/A | Compile OK | Score: N/A | 显示更多 |
Testcase #1 | 36.35 us | 40 KB | Accepted | Score: 10 | 显示更多 |
Testcase #2 | 43.72 us | 40 KB | Accepted | Score: 10 | 显示更多 |
Testcase #3 | 38.12 us | 40 KB | Accepted | Score: 10 | 显示更多 |
Testcase #4 | 38.14 us | 40 KB | Accepted | Score: 10 | 显示更多 |
Testcase #5 | 46.32 us | 40 KB | Accepted | Score: 10 | 显示更多 |
Testcase #6 | 116.69 us | 44 KB | Accepted | Score: 10 | 显示更多 |
Testcase #7 | 502.28 us | 52 KB | Accepted | Score: 10 | 显示更多 |
Testcase #8 | 4.783 ms | 112 KB | Accepted | Score: 10 | 显示更多 |
Testcase #9 | 39.651 ms | 364 KB | Accepted | Score: 10 | 显示更多 |
Testcase #10 | 79.012 ms | 684 KB | Accepted | Score: 10 | 显示更多 |
Judge Duck Online | 评测鸭在线
Server Time: 2024-12-05 10:22:07 | Loaded in 1 ms | Server Status
个人娱乐项目,仅供学习交流使用 | 捐赠