# |
Submission time |
Handle |
Problem |
Language |
Result |
Execution time |
Memory |
73233 |
2018-08-28T05:37:49 Z |
nvmdava |
Wiring (IOI17_wiring) |
C++17 |
|
0 ms |
0 KB |
//#include "wiring.h"
#include <bits/stdc++.h>
using namespace std;
int a[200001];
long long min_total_length(std::vector<int> r, std::vector<int> b) {
if(r.back() < b.back()){
swap(r, b);
}
a[0] = 0;
a[b.size()] = r.size();
long long ans = 0;
for(int i = 1; i < b.size(); i++){
a[i] = upper_bound(r.begin(), r.end(), (b[i] + b[i - 1]) / 2) - r.begin();
}
for(int i = 0; i < b.size(); i++){
for(int j = a[i]; j < a[i + 1]; j++){
ans += (long long) abs(r[j] - b[i]);
}
}
return ans;
}
int main() {
int n, m;
assert(2 == scanf("%d %d", &n, &m));
vector<int> r(n), b(m);
for(int i = 0; i < n; i++)
assert(1 == scanf("%d", &r[i]));
for(int i = 0; i < m; i++)
assert(1 == scanf("%d", &b[i]));
long long res = min_total_length(r, b);
printf("%lld\n", res);
return 0;
}
Compilation message
wiring.cpp: In function 'long long int min_total_length(std::vector<int>, std::vector<int>)':
wiring.cpp:16:19: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
for(int i = 1; i < b.size(); i++){
~~^~~~~~~~~~
wiring.cpp:19:19: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
for(int i = 0; i < b.size(); i++){
~~^~~~~~~~~~
/tmp/cc3Rue1X.o: In function `main':
grader.cpp:(.text.startup+0x0): multiple definition of `main'
/tmp/ccqLCVvZ.o:wiring.cpp:(.text.startup+0x0): first defined here
collect2: error: ld returned 1 exit status