[Offer收割]编程练习赛24 register

Ended

Participants:356

Verdict:Accepted
Score:100 / 100
Submitted:2017-08-27 14:05:27

Lang:G++

Edit
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
#include <stdio.h>
#include <iostream>
#include <algorithm>
#include <string>
#include <vector>
#include <string.h>
#include <math.h>
using namespace std;
typedef long long ll;
const int N = 1e6;
int a[N], que[N], dis[N];
int n, m;
ll f(int l, int r, int x) {
    ll rt = 0;
    for (int i = l; i <= r; i++)
        rt += abs(que[i] - que[x]);
    return rt;
}
ll getMinDis(int l, int r) {
    ll rt = 1e11;
    int L = l, R = r;
    int mid = (l + r) / 2;
    rt = min(rt, f(L, R, mid));
    return rt;
}
int main() {
    int kongwei = 0;
    cin >> n >> m;
    for (int i = 0; i<n; i++) {
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX