結果
| 問題 |
No.1095 Smallest Kadomatsu Subsequence
|
| コンテスト | |
| ユーザー |
|
| 提出日時 | 2020-06-26 22:42:03 |
| 言語 | C++14 (gcc 13.3.0 + boost 1.87.0) |
| 結果 |
WA
|
| 実行時間 | - |
| コード長 | 887 bytes |
| コンパイル時間 | 1,661 ms |
| コンパイル使用メモリ | 172,996 KB |
| 実行使用メモリ | 14,592 KB |
| 最終ジャッジ日時 | 2024-07-04 22:34:22 |
| 合計ジャッジ時間 | 5,151 ms |
|
ジャッジサーバーID (参考情報) |
judge5 / judge2 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 3 |
| other | AC * 5 WA * 25 |
ソースコード
#include <bits/stdc++.h>
using namespace std;
#define int long long
template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; }
signed main(){
int n;
cin >> n;
int a[200010];
set<int> l, r;
for(int i = 0;i < n;i++){
cin >> a[i];
r.insert(a[i]);
}
int ans = LLONG_MAX;
l.insert(a[0]);
r.erase(a[0]);
for(int i = 1;i < n-1;i++){
r.erase(a[i]);
{
int lnum = *l.begin();
int rnum = *r.begin();
if(lnum < a[i] && rnum < a[i]){
ans = min(ans, lnum + a[i] + rnum);
}
}
{
auto lnum = l.upper_bound(a[i]);
auto rnum = r.upper_bound(a[i]);
if(lnum != l.end() && rnum != r.end()){
ans = min(ans, *lnum + a[i] + *rnum);
}
}
}
if(ans == LLONG_MAX){
cout << -1 << endl;
}else{
cout << ans << endl;
}
return 0;
}