답안 #73384

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
73384 2018-08-28T08:06:43 Z 강태규(#2268) Radio (Balkan15_RADIO) C++11
30 / 100
75 ms 4704 KB
#include <iostream>
#include <algorithm>
#include <vector>
#include <queue>
#include <deque>
#include <set>
#include <map>
#include <unordered_map>
#include <functional>
#include <cstring>
#include <cmath>
#include <ctime>
#include <cstdlib>

using namespace std;
typedef long long llong;
typedef long double ld;
typedef pair<int, int> pii;
typedef pair<llong, llong> pll;

struct event {
    int x, t, i;
    bool operator<(const event &p) const {
        return x < p.x;
    }
};

int n, k;
int x[100001];
int p[100001];
int s[100001];

const llong inf = 1e18;
int main() {
    vector<event> ev;
    scanf("%d%d", &n, &k);
    int lcnt = 0, rcnt = n;
    llong lsum = 0, rsum = 0;
    for (int i = 1; i <= n; ++i) {
        scanf("%d%d%d", x + i, p + i, s + i);
        ev.push_back({ x[i] - p[i], 0, i });
        ev.push_back({ x[i] + p[i], 1, i });
        rsum += x[i] - p[i];
    }
    sort(ev.begin(), ev.end());
    
    llong ans = inf;
    for (event e : ev) {
        int px = e.x;
        ans = min(ans, (llong)lcnt * px - lsum + rsum - (llong)rcnt * px);
        if (e.t) {
            ++lcnt;
            lsum += x[e.i] + p[e.i];
        }
        else {
            --rcnt;
            rsum -= x[e.i] - p[e.i];
        }
    }
    printf("%lld\n", ans);
    
	return 0;
}

Compilation message

code1.cpp: In function 'int main()':
code1.cpp:36:10: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
     scanf("%d%d", &n, &k);
     ~~~~~^~~~~~~~~~~~~~~~
code1.cpp:40:14: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
         scanf("%d%d%d", x + i, p + i, s + i);
         ~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Incorrect 2 ms 376 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 3 ms 376 KB Output is correct
2 Correct 3 ms 440 KB Output is correct
3 Correct 2 ms 488 KB Output is correct
4 Correct 3 ms 540 KB Output is correct
5 Correct 4 ms 564 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Incorrect 2 ms 564 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 7 ms 884 KB Output is correct
2 Correct 18 ms 1744 KB Output is correct
3 Correct 52 ms 2564 KB Output is correct
4 Correct 75 ms 4568 KB Output is correct
5 Correct 52 ms 4704 KB Output is correct
6 Correct 74 ms 4704 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Incorrect 5 ms 4704 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 2 ms 4704 KB Output isn't correct
2 Halted 0 ms 0 KB -