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

Garden

Unrated 레이팅 미적용
난이도
0.500s
시간 제한
32MB
메모리 제한
0
맞았습니다!!
0
제출 수
0.0%
정답률
레이팅

의견: 0

설명

Task: GAR
Garden
Saturday, 20–08–2005
Available memory: 32 MB. Maximum running time: 0.5 s.
Byteman owns the most beautiful garden in Bytetown. He planted n roses in his garden. Summer has come
and the flowers have grown big and beautiful. Byteman has realized that he is not able to take care of all the
roses on his own. He has decided to employ two gardeners to help him. He wants to select two rectangular
areas, so that each of the gardeners will take care of the roses inside one area. The areas should be disjoint
and each should contain exactly k roses.
Byteman wants to make a fence surrounding the rectangular areas, but he is short of money, so he wants
to use as little fence as possible. Your task is to help Byteman select the two rectangular areas.
The garden forms a rectangle l meters long and w meters wide. It is divided into l · w squares of size
1 meter × 1 meter each. We fix a coordinate system with axes parallel to the sides of the garden. All squares
have integer coordinates (x,y) satisfying 1 ≤x ≤l, 1 ≤y ≤w. Each square may contain any number of roses.
The rectangular areas, which must be selected, should have their sides parallel to the sides of the garden
and the squares in their corners should have integer coordinates. For 1 ≤l1 ≤l2 ≤l and 1 ≤w1 ≤w2 ≤w, a
rectangular area with corners (l1,w1), (l1,w2), (l2,w1) and (l2,w2):
• contains all the squares with coordinates (x,y) satisfying l1 ≤x ≤l2 and w1 ≤y ≤w2, and
• has perimeter 2 ·(l2 −l1 +1)+2 ·(w2−w1 +1).
The two rectangular areas must be disjoint, that is they cannot contain a common square. Even if they have a
common side, or part of it, they must be surrounded by separate fences.
Task
Write a program, that:
• reads from the standard input the dimensions of the garden, the number of roses in the garden, the
number of roses that should be in each of the rectangular areas, and the positions of the roses,
• finds the corners of two such rectangular areas with minimum sum of perimeters that satisfy the given
conditions,
• writes to the standard output the minimum sum of perimeters of two non-overlapping rectangular areas,
each containing exactly the given number of roses (or a single word NO, if no such pair of areas exists).

Example

For the input data:
6 5
7 3
3 4
3 3
6 1
1 1
5 5
5 5
3 1
the correct result is:
22
1
2
3
4
5
6
1
2
3
4
5
v. 1.05
2/2
Garden

Note (RiseOJ) — The original statement describes file-based input/output; on this judge your program must read from standard input and write to standard output instead.

제약
입력 형식

The first line of standard input contains two integers: l and w (1 ≤l,w ≤250) separated by a single space
— the length and the width of the garden. The second line contains two integers: n and k (2 ≤n ≤5000,
1 ≤k ≤n/2) separated by a single space — the number of roses in the garden and the number of roses that
should be in each of the rectangular areas. The following n lines contain the coordinates of the roses, one rose
per line. The (i+2)-nd line contains two integers li, wi (1 ≤li ≤l, 1 ≤wi ≤w) separated by a single space
— the coordinates of the square containing the i-th rose. Two or more roses can occur in the same square.
In 50% of test cases, the dimensions of the garden will satisfy l,w ≤40.
v. 1.05
½
Garden

출력 형식

The standard output should contain only one line with exactly one integer — the minimum sum of perimeters
of two non-overlapping rectangular areas, each containing exactly k roses, or a single word NO, if no such pair
of areas exists.

문제 정보

생성자가 기록되지 않았습니다.

출처 IOI 2005

평가 및 의견

Garden

개요
출제자 난이도 Unrated 레이팅 미적용 의견 0 / 50 공개 집계 (커뮤니티 난이도, 주요 주제, 품질)는 의견이 충분히 모이면 공개됩니다.

Log in to rate problems.

개별 의견

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

풀이 제출

Garden

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