Submission #1091648

#TimeUsernameProblemLanguageResultExecution timeMemory
1091648ASN49KSafety (NOI18_safety)C++14
66 / 100
2032 ms2000 KiB
#include <bits/stdc++.h> using namespace std; using i64=long long; #define UNUSED -1 #define all(x) x.begin(),x.end() #define pb push_back const int mod=1e9+7,inf=1e9+1; const int N=2e5; int n,h; int main() { ios::sync_with_stdio(false); cin.tie(0); cin>>n>>h; vector<i64>b; i64 rez=0; int last_l=0,last_r=0; for(int i=1;i<=n;i++) { int x; cin>>x; b.insert(lower_bound(all(b) , x),x); b.insert(lower_bound(all(b) , x),x); for(int j=0;j<i;j++) { b[j]-=h; } for(int j=i;j<2*i;j++) { b[j]+=h; } //rez se schimba, intervale disjuncte if(i!=1) { rez+=max(last_l-x , 0); rez+=max(x-last_r , 0); } last_l=b[i-1],last_r=b[i]; } cout<<rez; }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...