이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include <stdio.h>
#define N 200000
#define M 100000
#define INF 0x3f3f3f3f3f3f3f3fLL
long long min(long long a, long long b) { return a < b ? a : b; }
long long max(long long a, long long b) { return a > b ? a : b; }
int main() {
static int ll[M], rr[M], ww[M];
static long long vv[N];
int n, m, h, i, j, r, tmp;
long long v, w, x, y, z, ans;
scanf("%d%d", &n, &m), n--;
x = 0;
for (h = 0; h < m; h++) {
scanf("%d%d%d", &ll[h], &rr[h], &ww[h]), ll[h]--, rr[h]--;
if (ll[h] > rr[h])
tmp = ll[h], ll[h] = rr[h], rr[h] = tmp;
vv[ll[h]] -= ww[h], vv[rr[h]] += ww[h];
x += ww[h];
}
for (i = 1; i < n; i++)
vv[i] += vv[i - 1];
v = -INF;
for (i = 0; i < n; i++)
v = max(v, vv[i]);
for (i = 0; i < n; i++)
vv[i] = v - vv[i];
ans = INF;
for (r = 0; r < 2; r++) {
y = INF;
for (i = 0; i < n; i++) {
w = 0;
for (h = 0; h < m; h++)
if (rr[h] <= i || i + 1 <= ll[h])
w += ww[h];
y = min(y, w + (vv[i] + r) / 2);
}
z = INF;
for (i = 0; i < n; i++)
for (j = i + 1; j < n; j++) {
w = 0;
for (h = 0; h < m; h++)
if (rr[h] <= i || i + 1 <= ll[h] && rr[h] <= j || j + 1 <= ll[h])
w += ww[h];
z = min(z, w + (vv[i] + r) / 2 + (vv[j] + r) / 2);
}
ans = min(ans, x - min(min(x, y), z) + v + r);
}
printf("%lld\n", ans);
return 0;
}
컴파일 시 표준 에러 (stderr) 메시지
arranging_tickets.c: In function 'main':
arranging_tickets.c:16:2: warning: ignoring return value of 'scanf' declared with attribute 'warn_unused_result' [-Wunused-result]
16 | scanf("%d%d", &n, &m), n--;
| ^~~~~~~~~~~~~~~~~~~~~
arranging_tickets.c:19:3: warning: ignoring return value of 'scanf' declared with attribute 'warn_unused_result' [-Wunused-result]
19 | scanf("%d%d%d", &ll[h], &rr[h], &ww[h]), ll[h]--, rr[h]--;
| ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |