Submission #200203

#TimeUsernameProblemLanguageResultExecution timeMemory
200203wilwxkSafety (NOI18_safety)C++14
5 / 100
63 ms6008 KiB
#include <bits/stdc++.h> using namespace std; typedef long long ll; const int MAXN = 2e5+5; int v[MAXN]; ll pre[MAXN], pos[MAXN]; int n, x; int main() { scanf("%d %d", &n, &x); for(int i = 1; i <= n; i++) scanf("%d", &v[i]); sort(v+1, v+1+n); for(int i = 1; i <= n; i++) pre[i] = pre[i-1]+v[i]; for(int i = n; i >= 1; i--) pos[i] = pos[i+1]+v[i]; ll ans = 1e18; for(int i = 1; i <= n; i++) { ll val = v[i]*ll(i-1); val -= pre[i-1]; val += pos[i+1]; val -= v[i]*ll(n-i); ans = min(ans, val); } printf("%lld\n", ans); }

Compilation message (stderr)

safety.cpp: In function 'int main()':
safety.cpp:11:7: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
  scanf("%d %d", &n, &x);
  ~~~~~^~~~~~~~~~~~~~~~~
safety.cpp:12:35: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
  for(int i = 1; i <= n; i++) scanf("%d", &v[i]);
                              ~~~~~^~~~~~~~~~~~~
#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...