Submission #1091645

#TimeUsernameProblemLanguageResultExecution timeMemory
1091645ASN49KSafety (NOI18_safety)C++14
66 / 100
2037 ms2196 KiB
#include <bits/stdc++.h> using namespace std; #define int long long 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; main() { ios::sync_with_stdio(false); cin.tie(0); cin>>n>>h; vector<int>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 , 0LL); rez+=max(x-last_r , 0LL); } last_l=b[i-1],last_r=b[i]; } cout<<rez; }

Compilation message (stderr)

safety.cpp:12:1: warning: ISO C++ forbids declaration of 'main' with no type [-Wreturn-type]
   12 | main()
      | ^~~~
#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...