Skip to content

Commit

Permalink
add BOI7SEQ
Browse files Browse the repository at this point in the history
  • Loading branch information
t3nsor committed Apr 29, 2016
1 parent f07542c commit 0ca4593
Showing 1 changed file with 39 additions and 0 deletions.
39 changes: 39 additions & 0 deletions boi7seq.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
// 2016-04-28
#include <cstdio>
#include <vector>
using namespace std;
int input() {
int res = 0; char c;
do {
c = getchar_unlocked();
} while (c <= 32);
do {
res = res*10 + c - '0';
c = getchar_unlocked();
} while (c > 32);
return res;
}
int main() {
int n = input();
long long total = 0;
vector<int> stk;
stk.push_back(input());
for (int i = 1; i < n; i++) {
int x = input();
if (x >= stk.back()) {
while (stk.size() >= 1 && x >= stk.back()) {
stk.pop_back();
if (stk.empty() || x < stk.back()) {
total += x;
} else {
total += stk.back();
}
}
}
stk.push_back(x);
}
for (int i = 0; i+1 < stk.size(); i++) {
total += stk[i];
}
printf("%lld\n", total);
}

0 comments on commit 0ca4593

Please sign in to comment.