Submission #137824

#TimeUsernameProblemLanguageResultExecution timeMemory
137824SirCenessSafety (NOI18_safety)C++14
5 / 100
167 ms4328 KiB
#include <bits/stdc++.h> using namespace std; #define mod 1000000007 #define mp make_pair #define pb push_back #define bas(x) #x << ": " << x << " " #define prarr(x, n) cout << #x << ": "; for (int qsd = 0; qsd < n; qsd++) cout << x[qsd] << " "; cout << endl; #define prarrv(x) cout << #x << ": "; for (int qsd = 0; qsd < (int)x.size(); qsd++) cout << x[qsd] << " "; cout << endl; #define ppair(x) "(" << x.first << ", " << x.second << ")" #define inside sl<=l&&r<=sr #define outside sr<l||r<sl typedef long long ll; int main(){ //freopen("in", "r", stdin); //freopen("out", "w", stdout); ll n, h; cin >> n >> h; vector<ll> arr(n); for (int i = 0; i < n; i++){ cin >> arr[i]; } vector<ll> a; a.pb(arr[0]); ll ekle = 0; for (int i = 1; i < n; i++){ if (abs(arr[i] - arr[i-1]) > h){ a.pb(arr[i] + ekle); } else { ekle += arr[i-1] - arr[i]; a.pb(arr[i] + ekle); } } //prarrv(a); vector<int> fark(a.size()); fark[0] = 0; for (int i = 1; i < a.size(); i++){ if (a[i] > a[i-1]) fark[i] = fark[i-1]+h; else if (a[i] < a[i-1]) fark[i] = fark[i-1]-h; else { fark[i] = fark[i-1]; } } //prarrv(fark); for (int i = 0; i < n; i++) a[i] -= fark[i]; sort(a.begin(), a.end()); ll med = a[a.size()/2]; ll ans = 0; for (int i = 0; i < a.size(); i++) ans += abs(a[i] - med); cout << ans << endl; }

Compilation message (stderr)

safety.cpp: In function 'int main()':
safety.cpp:43:20: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
  for (int i = 1; i < a.size(); i++){
                  ~~^~~~~~~~~~
safety.cpp:56:20: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
  for (int i = 0; i < a.size(); i++) ans += abs(a[i] - med);
                  ~~^~~~~~~~~~
#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...