제출 #29036

#제출 시각아이디문제언어결과실행 시간메모리
29036kajebiiiArranging Tickets (JOI17_arranging_tickets)C++14
85 / 100
559 ms8452 KiB
#include <stdio.h> #include <bits/stdc++.h> using namespace std; #define SZ(v) ((int)(v).size()) #define ALL(v) (v).begin(),(v).end() #define one first #define two second typedef long long ll; typedef pair<int, int> pi; typedef pair<ll, int> pli; typedef pair<ll, pi> plp; typedef tuple<int, int, int> ti; typedef tuple<ll, int, int> tli; const int INF = 0x3f2f1f0f; const ll LINF = 1ll * INF * INF; const int MAX_N = 2e5 + 100, MAX_M = 1e5 + 100, MAX_C = 1e9 + 100; int N, M; ti Nr[MAX_M]; ll Sum[MAX_N], Temp[MAX_N], maxV; bool isCan(ll use, ll lim) { ll up = lim - use; // printf("[%lld %lld] [up %lld]\n", use, lim, up); ll cnt = 0; priority_queue<pi> Q; for(int i=0; i<=N; i++) Temp[i] = 0; for(int i=1, j=0; i<=N; i++) { Temp[i] += Temp[i-1]; while(j < M && get<0>(Nr[j]) == i) Q.push(pi(get<1>(Nr[j]), get<2>(Nr[j]))), j++; ll now = Sum[i] + Temp[i]; // printf("i %d : now %lld (%lld %lld)\n", i, now, Sum[i], Temp[i]); while(!Q.empty() && now > up) { int y, c; tie(y, c) = Q.top(); Q.pop(); int v = min((ll)c, now - up ); Temp[i] -= 2 * v; Temp[y] += 2 * v; cnt += v; now -= 2 * v; if(c - v > 0) Q.push(pi(y, c-v)); // printf("now %lld -> %lld\n", now+v, now); } if(now > up) return false; if(cnt > use) return false; } return true; } int main() { cin >> N >> M; for(int i=0; i<M; i++) { int x, y, c; scanf("%d%d%d", &x, &y, &c); if(x > y) swap(x, y); Nr[i] = ti(x, y, c); Sum[x] += c; Sum[y] -= c; } sort(Nr, Nr+M); for(int i=1; i<=N; i++) Sum[i] += Sum[i-1], maxV = max(maxV, Sum[i]); ll ans = -1; for(ll l=0, r=maxV; l<=r; ) { ll m = (l+r) >> 1; if(isCan(maxV-m, m) || isCan(maxV-m+1, m)) ans = m, r = m-1; else l = m+1; } printf("%lld\n", ans); return 0; }

컴파일 시 표준 에러 (stderr) 메시지

arranging_tickets.cpp: In function 'int main()':
arranging_tickets.cpp:50:43: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
   int x, y, c; scanf("%d%d%d", &x, &y, &c);
                                           ^
#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...