結果
| 問題 |
No.1095 Smallest Kadomatsu Subsequence
|
| コンテスト | |
| ユーザー |
milanis48663220
|
| 提出日時 | 2020-06-26 21:36:26 |
| 言語 | C++14 (gcc 13.3.0 + boost 1.87.0) |
| 結果 |
AC
|
| 実行時間 | 336 ms / 2,000 ms |
| コード長 | 1,849 bytes |
| コンパイル時間 | 783 ms |
| コンパイル使用メモリ | 87,340 KB |
| 実行使用メモリ | 13,696 KB |
| 最終ジャッジ日時 | 2024-07-04 19:57:25 |
| 合計ジャッジ時間 | 4,590 ms |
|
ジャッジサーバーID (参考情報) |
judge4 / judge2 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 3 |
| other | AC * 30 |
ソースコード
#include <iostream>
#include <algorithm>
#include <iomanip>
#include <vector>
#include <queue>
#include <set>
#include <map>
using namespace std;
typedef long long ll;
int N;
int A[200000];
int main(){
ios::sync_with_stdio(false);
cin.tie(0);
cout << setprecision(10) << fixed;
cin >> N;
for(int i = 0; i < N; i++) {
cin >> A[i];
A[i] *= -1;
}
int ans = -1e9;
multiset<int> stl, str;
stl.insert(A[0]);
for(int i = 2; i < N; i++) str.insert(A[i]);
for(int i = 1; i < N-1; i++){
// < >
auto l = stl.lower_bound(A[i]);
auto r = str.lower_bound(A[i]);
if(l != stl.begin() && r != str.begin()){
l--; r--;
if(*l != *r){
ans = max(ans, *l+*r+A[i]);
}else{
if(l != stl.begin()){
l--;
ans = max(ans, *l+*r+A[i]);
l++;
}
if(r != stl.begin()){
r--;
ans = max(ans, *l+*r+A[i]);
r++;
}
}
}
// > <
l = stl.end(); l--;
r = str.end(); r--;
if(*l > A[i] && *r > A[i]){
if(*l != *r){
ans = max(ans, *l+*r+A[i]);
}else{
if(l != stl.begin()){
l--;
if(*l > A[i]) ans = max(ans, *l+*r+A[i]);
l++;
}
if(r != stl.begin()){
r--;
if(*r > A[i]) ans = max(ans, *l+*r+A[i]);
r++;
}
}
}
stl.insert(A[i]);
str.erase(str.find(A[i+1]));
}
if(ans == -1e9){
cout << -1 << endl;
}else{
cout << -ans << endl;
}
}
milanis48663220