結果
| 問題 | No.1734 Decreasing Elements |
| コンテスト | |
| ユーザー |
platinum
|
| 提出日時 | 2021-08-18 16:30:56 |
| 言語 | C++17 (gcc 13.3.0 + boost 1.89.0) |
| 結果 |
AC
|
| 実行時間 | 398 ms / 3,000 ms |
| コード長 | 917 bytes |
| 記録 | |
| コンパイル時間 | 2,349 ms |
| コンパイル使用メモリ | 206,700 KB |
| 最終ジャッジ日時 | 2025-01-23 22:56:14 |
|
ジャッジサーバーID (参考情報) |
judge4 / judge3 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 3 |
| other | AC * 24 |
ソースコード
#include <bits/stdc++.h>
#define rep(i,n) for(int i = 0; i < (int)(n); i++)
using namespace std;
using LL = long long;
using P = pair<int,int>;
using vv = vector<vector<int>>;
const int INF = (int)1e9;
const LL LINF = (LL)1e18;
const int A_Max = (int)4e5;
int main(){
int N;
cin >> N;
assert(1 <= N and N <= 200000);
vector<int> A(N);
rep(i,N) cin >> A[i];
rep(i,N) assert(0 <= A[i] and A[i] <= 200000);
priority_queue<P> q;
set<int> st;
st.insert(0);
q.push(P(A_Max, 0));
int ans = N;
rep(i,N){
auto itr = st.upper_bound(A[i]);
itr--;
int a = A[i] - *itr;
if(a == 0){
ans--;
continue;
}
int siz = q.size();
vector<P> res;
rep(j,siz){
P p = q.top();
if(p.first <= a) break;
q.pop();
res.emplace_back(a, p.second);
res.emplace_back(p.first - a, p.second + a);
st.insert(p.second + a);
}
rep(j,res.size()) q.push(res[j]);
}
cout << ans << endl;
return 0;
}
platinum