RiseOJ는 solved.ac와 제휴 관계가 없습니다. 티어 아이콘 © solved.ac. solved.ac
포럼
USACO0679

Mooclear Reactor

Silver II 실버 II
난이도
2s
시간 제한
256MB
메모리 제한
0
맞았습니다!!
0
제출 수
0.0%
정답률
레이팅

의견: 0

설명

Bessie is designing a nuclear reactor to power Farmer John's lucrative new AI
data center business, CowWeave!

The reactor core consists of \(N\) (\(1\le N \le 2\cdot 10^5\)) fuel rods, numbered
\(1\) through \(N\). The \(i\)-th rod has a "stable operating range" \([l_i, r_i]\)
(\(-10^9 \leq l_i \leq r_i \leq 10^9\)), meaning it can only generate power if its
energy \(a_i\) (chosen by Bessie) satisfies \(l_i \le a_i \le r_i\); otherwise, it
sits idle and does not generate power. Moreover, \(a_i\) must always be an
integer. Note that \(a_i\) can be any integer, not limited to
\([-10^9, 10^9]\).

However, quantum interactions between the rods mean that there are \(M\)
constraints of the form \((x, y, z)\) where Bessie must satisfy \(a_x + a_y = z\)
(\(1 \leq x,y \leq N\) and \(-10^9\le z\le 10^9\)) to prevent the reactor from
melting down.

Help Bessie find the maximum number of power-generating rods she can achieve in
her design without it melting down!

Problem credits: Akshaj Arora

제약

SCORING

  • Input 4: \(x = y\) for all constraints.
  • Inputs 5-7: \(|x-y|=1\) for all constraints.
  • Inputs 8-10: \(|x-y|\le 1\) for all constraints.
  • Inputs 11-13: No additional conditions.

Problem credits: Akshaj Arora

입력 형식

The first line contains \(T\) (\(1\le T\le 10\)), the number of independent tests.
Each test is specified in the following format:

  • The first line contains the two integers \(N\) and \(M\).
  • The second line contains the \(N\) integers \(l_1, \dots, l_N\).
  • The third line contains the \(N\) integers \(r_1, \dots, r_N\).
  • The next \(M\) lines each contain three integers \(x\), \(y\), and \(z\), each representing a constraint.

It is guaranteed that neither the sum of \(N\) nor the sum of \(M\) over all tests
exceeds \(4\cdot 10^5\).

출력 형식

If no choice of rod energies exists that satisfies all constraints, output \(-1\).
Otherwise, output the maximum number of power-generating rods Bessie can
achieve.

예제 1
입력
2
3 3
1 2 3
1 2 3
1 1 2
2 2 10
1 1 4
3 2
1 2 3
1 2 3
1 1 2
2 2 10
출력
-1
2
설명

In the second test, the constraints require that:

  1. \(a_1 + a_1 = 2\)
  2. \(a_2 + a_2 = 10\)

Choosing energies \(a=[1, 5, 3]\) results in \(2\) power-generating rods because:

  • \(l_1 = 1 \leq a_1 \leq 1 = r_1\)
  • \(l_3 = 3 \leq a_3 \leq 3 = r_3\)

and \(a\) satisfies all required constraints.

예제 2
입력
1
3 2
10 -10 10
10 -10 10
1 2 0
2 3 0
출력
3
설명

Choosing rod energies \(a=[10, -10, 10]\) results in \(3\) power-generating rods.

예제 3
입력
5
3 3
1 -1 0
2 1 2
1 2 1
1 3 4
2 3 3
1 1
-100
100
1 1 3
1 1
-100
100
1 1 2
1 2
-100
100
1 1 2
1 1 4
1 2
-100
100
1 1 2
1 1 2
출력
2
-1
1
-1
1
문제 정보

riseoj 작성

출처 올림피아드 > USACO > 2025-2026 > First Contest > Silver

태그

평가 및 의견

Mooclear Reactor

개요
출제자 난이도 Silver II 실버 II 의견 0 / 50 공개 집계 (커뮤니티 난이도, 주요 주제, 품질)는 의견이 충분히 모이면 공개됩니다.

Log in to rate problems.

개별 의견

아직 의견이 없습니다. 자격이 된다면 위 양식에서 가장 먼저 평가해 보세요.

풀이 제출

Mooclear Reactor

게스트로 둘러보고 있습니다. 로그인하면 풀이를 제출하고 진행 상황을 확인할 수 있습니다. 로그인하고 제출하기
공개
C++20 Tab 들여쓰기 · Ctrl+/ 주석 토글 · Enter 자동 들여쓰기
1 1 1 0 공백: 4 · UTF-8