0% found this document useful (0 votes)
114 views

Trư NG ĐH Bách Khoa Hà N I: A. 05. Gold Mining

Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
114 views

Trư NG ĐH Bách Khoa Hà N I: A. 05. Gold Mining

Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 28

Trường ĐH Bách Khoa Hà Nội |

Thuật toán ứng dụng 0460183554HuyNQ | Logout


=> Hướng dẫn

HOME TOP CONTESTS GYM PROBLEMSET GROUPS RATING EDU API CALENDAR HELP

PROBLEMS SUBMIT CODE MY SUBMISSIONS STATUS STANDINGS CUSTOM INVOCATION

ĐH Bách Khoa Hà Nội


A. 05. GOLD MINING Private
time limit per test: 1 second
Participant
memory limit per test: 256 megabytes
input: standard input
output: standard output

The Kingdom ALPHA has n warehouses of golds located on a straight line and are numbered → About Group
1, 2, . . . , n . The warehouse i has amount of ai (ai is non-negative integer) and is located at

coordinate i (i = 1, . . . , n ). The King of ALPHA opens a competition for hunters who are
responsible to find a subset of gold warehouses having largest total amount of golds with
respect to the condition that the distance between two selected warehouses must be greater
than or equal to L 1 and less than or equal to L 2 .

Input

Line 1 contains n, L 1 , and L 2 (1 ≤ n ≤ 100000, 1 ≤ L1 ≤ L2 ≤ n )

Line 2 contains n integers a1 , a2 , … , an

Output
Contains only one single integer denoting the total amount of golds of selected warehouses.

Example
input Copy

6 2 3
3 5 9 6 7 4
Trang nộp bài trực tuyến dành cho sinh viên
output Copy tham gia môn học "Thuật toán ứng dụng" của
Viện CNTT-TT, Đại học BKHN
19

Group website

Training 5 - Dynamic
Programming - 20201
Contest is running
9 months
Contestant

→ Submit?

Language: GNU G++17 7.3.0

Choose
Choose File No file chosen
file:

Submit

→ Last submissions
Submission Time Verdict
100095317 Dec/01/2020 Perfect result:
11:39 100 points
 Dec/01/2020 Partial result: 60
100095042
11:35 points

→ Your points
Points

A 100

C
E

F 80

G
I

K
L

P 100

Q
R 100

S 100

Total 480

Codeforces (c) Copyright 2010-2021 Mike Mirzayanov


The only programming contests Web 2.0 platform
Server time: Jan/13/2021 23:35:45UTC+7 (h2).
Desktop version, switch to mobile version.
Privacy Policy

Supported by

Trường ĐH Bách Khoa Hà Nội |

Thuật toán ứng dụng 0460183554HuyNQ | Logout


=> Hướng dẫn

HOME TOP CONTESTS GYM PROBLEMSET GROUPS RATING EDU API CALENDAR HELP

PROBLEMS SUBMIT CODE MY SUBMISSIONS STATUS STANDINGS CUSTOM INVOCATION

ĐH Bách Khoa Hà Nội


B. NETWORKS Private
time limit per test: 1 second
Participant
memory limit per test: 256 megabytes
input: standard input
output: standard output

The network administrator of a company have to analyze the current state of their → About Group
communication network all over the world. The communication network consists of servers
and cable links between these servers, each link has a cost. A k -route is a sequence of
k + 1 different servers in which two consecutive servers are connected by a cable link. A

cycle is a k -route (for any k > 1) such that the beginning and the terminating servers are
connected by a cable link. The communication network contains no cycle. The cost of a k -
route is the sum of cost of links between two consecutive servers of the k -route. One of the
indicators of the analysis is the k -route having minimal cost of the network for a given value of
k.

Given the communication network G and an integral value k , help the network administrator
to find the k -route having minimal cost of G .

Input
The input consists of following lines

Line 1: contains two integer n and k (1 ≤ n ≤ 10000, 1 ≤ k ≤ 2000 ) in which n is


the number of servers of the communication network G (servers are numbered 1,2,...,n)
Line 2: contains an integer m (1 ≤ m ≤ 10000 ) which is the number of cable links
between servers of G Trang nộp bài trực tuyến dành cho sinh viên
th tham gia môn học "Thuật toán ứng dụng" của
Line i + 2: contains three integers u , v, and w: u and v are two end points of the i Viện CNTT-TT, Đại học BKHN
link of G (∀i = 1, … , m ), w is the cost of this link.
Group website
Output
The output contains the cost of the k -route found.
Training 5 - Dynamic
Example Programming - 20201
input Copy Contest is running
6 2
5 9 months
1 2 4
1 4 1 Contestant
1 5 3
1 6 2
2 3 1

output Copy
→ Submit?
3

Language: GNU G++17 7.3.0

Choose
Choose File No file chosen
file:

Submit

→ Your points
Points
A 100
B

C
E

F 80

G
I

L
P 100

R 100
S 100

Total 480

Codeforces (c) Copyright 2010-2021 Mike Mirzayanov


The only programming contests Web 2.0 platform
Server time: Jan/13/2021 23:35:56UTC+7 (h2).
Desktop version, switch to mobile version.
Privacy Policy

Supported by

Trường ĐH Bách Khoa Hà Nội |

Thuật toán ứng dụng 0460183554HuyNQ | Logout


=> Hướng dẫn

HOME TOP CONTESTS GYM PROBLEMSET GROUPS RATING EDU API CALENDAR HELP

PROBLEMS SUBMIT CODE MY SUBMISSIONS STATUS STANDINGS CUSTOM INVOCATION

ĐH Bách Khoa Hà Nội


C. GOLD MINING (HARD) Private
time limit per test: 1 second
Participant
memory limit per test: 256 megabytes
input: standard input
output: standard output

The Kingdom ALPHA has n warehouses of golds located on a straight line and are numbered → About Group
1, 2, ..., n. The warehouse i has amount of ai (ai is non-negative integer) and is located at
coordinate i (∀i = 1, … , n ). The King of ALPHA opens a competition for hunters who are
responsible to find a subset of gold warehouses having largest total amount of golds with
respect to the condition that the distance between two selected warehouses must be greater
than or equal to L 1 and less than or equal to L 2 .

Input
The input consists of the following lines:

Line 1 contains n, L 1 , and L 2 (1 ≤ n ≤ 1000000, 1 ≤ L 1 ≤ L 2 ≤ n ).

Line 2 contains n integers a1 , a2 , … , an

Output
Contains only one single integer denoting the total amount of golds of selected warehouses.

Example
input Copy

6 2 3 Trang nộp bài trực tuyến dành cho sinh viên


3 5 9 6 7 4 tham gia môn học "Thuật toán ứng dụng" của
Viện CNTT-TT, Đại học BKHN
output Copy

19 Group website

Training 5 - Dynamic
Programming - 20201
Contest is running
9 months
Contestant

→ Submit?

Language: GNU G++17 7.3.0

Choose
Choose File No file chosen
file:

Submit

→ Your points
Points
A 100
B

C
E

F 80

G
I

L
P 100

R 100
S 100

Total 480

Codeforces (c) Copyright 2010-2021 Mike Mirzayanov


The only programming contests Web 2.0 platform
Server time: Jan/13/2021 23:36:04UTC+7 (h2).
Desktop version, switch to mobile version.
Privacy Policy

Supported by

Trường ĐH Bách Khoa Hà Nội |

Thuật toán ứng dụng 0460183554HuyNQ | Logout


=> Hướng dẫn

HOME TOP CONTESTS GYM PROBLEMSET GROUPS RATING EDU API CALENDAR HELP

PROBLEMS SUBMIT CODE MY SUBMISSIONS STATUS STANDINGS CUSTOM INVOCATION

ĐH Bách Khoa Hà Nội


E. 05. MACHINE Private
time limit per test: 1 second
Participant
memory limit per test: 256 megabytes
input: standard input
output: standard output

An engineer needs to schedule a machine to run on some given periods 1, … , n to produce → About Group
a chemical product C . Each period i is represented by a starting time point si and terminating
time point ti (si < ti ). Due to a technical constraint, the machine must run on exactly two
periods that are not overlap (two periods i and j are not overlap if ti < sj or tj < si ). If the
machine is runned on the period i, then the amount of C it will produce is equal to the duration
of the period i (which is equal to ti − si ). Help the engineer to select two not-overlap periods
to run the machine such that the amount of C produced is maximal.

Input

Line 1: contains the positive integer n (2 ≤ n ≤ 2 ⋅ 10


6
)
Line i + 1: contains two positive integer si and ti (1 ≤ s i < t i ≤ 2 ⋅ 10
6
)

Output
The output consists of only one single integer which is the amount of product C the machine
will produce in the two selected periods. In case there is no solution (there does not exist two
periods that are not overlap), the output contains the value -1.

Example
input Copy Trang nộp bài trực tuyến dành cho sinh viên
tham gia môn học "Thuật toán ứng dụng" của
5 Viện CNTT-TT, Đại học BKHN
8 12
6 11 Group website
3 9
2 5
1 4
Training 5 - Dynamic
output Copy Programming - 20201
8 Contest is running
9 months
Contestant

→ Submit?

Language: GNU G++17 7.3.0

Choose
Choose File No file chosen
file:

Submit

→ Your points
Points
A 100
B

C
E

F 80

G
I

L
P 100

R 100
S 100

Total 480

Codeforces (c) Copyright 2010-2021 Mike Mirzayanov


The only programming contests Web 2.0 platform
Server time: Jan/13/2021 23:36:14UTC+7 (h2).
Desktop version, switch to mobile version.
Privacy Policy

Supported by

Trường ĐH Bách Khoa Hà Nội |

Thuật toán ứng dụng 0460183554HuyNQ | Logout


=> Hướng dẫn

HOME TOP CONTESTS GYM PROBLEMSET GROUPS RATING EDU API CALENDAR HELP

PROBLEMS SUBMIT CODE MY SUBMISSIONS STATUS STANDINGS CUSTOM INVOCATION

ĐH Bách Khoa Hà Nội


F. 05. NURSE Private
time limit per test: 1 second
Participant
memory limit per test: 256 megabytes
input: standard input
output: standard output

The director of a hospital want to schedule a working plan for a nurse in a given period of N → About Group
consecutive days 1,..., N . Due to the policy of the hospital, each nurse cannot work all the
days 1,..., N . Instead, there must be days off in which the nurse need to take a rest. A
working plan is a sequence of disjoint working periods. A working period of a nurse is defined
to be a sequence of consecutive days on which the nurse must work and the length of the
working period is the number of consecutive days of that working period. The hospital imposes
two constraints:

Each nurse can take a rest only one day between two consecutive working periods. it
means that if the nurse takes a rest today, then she has to work tomorrow (1)
The length of each working period must be greater or equal to K1 and less than or equal
to K2 (2)

The director of the hospital want to know how many possible working plans satisfying above
constraint?
Input
The input consists of one line which contains 3 positive integers
N , K 1 , K 2 (N ≤ 1000, K 1 < K 2 ≤ 400)

Output Trang nộp bài trực tuyến dành cho sinh viên
tham gia môn học "Thuật toán ứng dụng" của
The output consists of only one single integer M modulo 109 + 7 where M is the total Viện CNTT-TT, Đại học BKHN
working plans satisfying the above constraints.
Group website
Example
input Copy
Training 5 - Dynamic
6 2 3 Programming - 20201
output Copy Contest is running
4
9 months
Contestant

→ Submit?

Language: GNU G++17 7.3.0

Choose
Choose File No file chosen
file:

Submit

→ Last submissions
Submission Time Verdict
101504986 Dec/17/2020 Partial result: 80
16:05 points

→ Your points
Points

A 100
B

F 80
G

J
K

P 100
Q

R 100

S 100
Total 480

Codeforces (c) Copyright 2010-2021 Mike Mirzayanov


The only programming contests Web 2.0 platform
Server time: Jan/13/2021 23:36:25UTC+7 (h2).
Desktop version, switch to mobile version.
Privacy Policy

Supported by

Trường ĐH Bách Khoa Hà Nội |

Thuật toán ứng dụng 0460183554HuyNQ | Logout


=> Hướng dẫn

HOME TOP CONTESTS GYM PROBLEMSET GROUPS RATING EDU API CALENDAR HELP

PROBLEMS SUBMIT CODE MY SUBMISSIONS STATUS STANDINGS CUSTOM INVOCATION

ĐH Bách Khoa Hà Nội


G. 05. MARBLE Private
time limit per test: 1 second
Participant
memory limit per test: 256 megabytes
input: standard input
output: standard output

Phong là một nhà điêu khắc, ông có một tấm đá cẩm thạch hình chữ nhật kích thước → About Group
W × H . Ông ta muốn cắt tấm đá thành các miếng hình chữ nhật kích thước

W1 × H1 , W2 × H2 , … , WN × HN . Ông ta muốn cắt đến tối đa các mẫu kích thước

có thể. Tấm đá có những vân đá cho nên không thể xoay khi sử dụng, có nghĩa là không thể
cắt ra miếng B × A thay cho miếng A × B trừ khi A = B. Các miếng phải được cắt tại
các điểm nguyên trên hàng cột và mỗi nhát cắt phải cắt đến hết hàng hoặc hết cột. Sau khi
cắt sẽ còn lại những mẩu đá còn thừa bỏ đi, nghĩa là những mẩu đá không thể cắt thành
miếng kích thước cho trước nào.

Yêu cầu: Hãy tìm cách cắt sao cho còn ít nhất diện tích đá thừa bỏ đi.

Hình dưới minh họa cách cắt các phiến đá trong ví dụ với diện tích thừa ít nhất tìm được là
10.

Famous sculptor Phong is making preparations to build a marvelous monument. For this
purpose he needs rectangular marble plates of sizes
W1 × H1 , W2 × H2 , … , WN × HN .

Recently, Phong has received a large rectangular marble slab. He wants to cut the slab to
obtain plates of the desired sizes. Any piece of marble (the slab or the plates cut from it) can
be cut either horizontally or vertically into two rectangular plates with integral widths and Trang nộp bài trực tuyến dành cho sinh viên
tham gia môn học "Thuật toán ứng dụng" của
heights, cutting completely through that piece. This is the only way to cut pieces and pieces Viện CNTT-TT, Đại học BKHN
cannot be joined together. Since the marble has a pattern on it, the plates cannot be rotated: if
Phong cuts a plate of size A × B then it cannot be used as a plate of size B × A unless Group website
A = B. He can make zero or more plates of each desired size. A marble plate is wasted if it
is not of any of the desired sizes after all cuts are completed. Phong wonders how to cut the
initial slab so that as little of it as possible will be wasted. Training 5 - Dynamic
Programming - 20201
As an example, assume that in the figure below the width of the original slab is 21 and the
height of the original slab is 11, and the desired plate sizes are 10 × 4, 6 × 2, 7 × 5 , and Contest is running
15 × 10. The minimum possible area wasted is 10, and the figure shows one sequence of 9 months
cuts with total waste area of size 10.
Contestant

→ Submit?

Language: GNU G++17 7.3.0

Choose
Choose File No file chosen
file:

Submit

Your task is to write a program that, given the size of the original slab and the desired plate
sizes, calculates the minimum total area of the original slab that must be wasted.
→ Your points
Input
Points
Dòng đầu tiên chứa hai số nguyên: W và H .
A 100
B
 Dòng thứ hai chứa một số nguyên N . N dòng tiếp theo mỗi dòng chứa hai số nguyên Wi
và Hi . C
E
The first line of input contains two integers: first W , the width of the original slab, and then H ,
F 80
the height of the original slab;
G
The second line contains one integer N : the number of desired plate sizes. The following N I
lines contain the desired plate sizes. Each of these lines contains two integers: first the width J
Wi and then the height Hi of that desired plate size (1 ≤ i ≤ N ).
K

Output L

Kết quả ghi ra duy nhất một số nguyên là tổng diện tích nhỏ nhất các miếng thừa bỏ đi. P 100

Q
For each dataset, write in one line a single integer: the minimum total area of the original slab
R 100
that must be wasted.
S 100

Scoring Total 480

1 ≤ W ≤ 600, 1 ≤ H ≤ 600, 0 < N ≤ 200, 1 ≤ Wi ≤ W , and


1 ≤ Hi ≤ H .

Có 50% số test ứng với W ≤ 20, H ≤ 20 và N ≤ 5.

Example
input Copy

21 11
4
10 4
6 2
7 5
15 10

output Copy

10

Codeforces (c) Copyright 2010-2021 Mike Mirzayanov


The only programming contests Web 2.0 platform
Server time: Jan/13/2021 23:36:35UTC+7 (h2).
Desktop version, switch to mobile version.
Privacy Policy

Supported by

Trường ĐH Bách Khoa Hà Nội |

Thuật toán ứng dụng 0460183554HuyNQ | Logout


=> Hướng dẫn

HOME TOP CONTESTS GYM PROBLEMSET GROUPS RATING EDU API CALENDAR HELP

PROBLEMS SUBMIT CODE MY SUBMISSIONS STATUS STANDINGS CUSTOM INVOCATION

ĐH Bách Khoa Hà Nội


I. 05. TOWER Private
time limit per test: 1 second
Participant
memory limit per test: 256 megabytes
input: standard input
output: standard output

Perhaps you have heard of the legend of the Tower of Babylon. Nowadays many details of this → About Group
tale have been forgotten. So now, in line with the educational nature of this contest, we will tell
you the whole story:

The babylonians had n types of blocks, and an unlimited supply of blocks of each type. Each
type-i block was a rectangular solid with linear dimensions (x i , yi , z i ) . A block could be
reoriented so that any two of its three dimensions determined the dimensions of the base and
the other dimension was the height. They wanted to construct the tallest tower possible by
stacking blocks. The problem was that, in building a tower, one block could only be placed on
top of another block as long as the two base dimensions of the upper block were both strictly
smaller than the corresponding base dimensions of the lower block. This meant, for example,
that blocks oriented to have equal-sized bases couldn't be stacked.

Your job is to write a program that determines the height of the tallest tower the babylonians
can build with a given set of blocks.

Input
The input file will contain one or more test cases. The first line of each test case contains an
integer n, representing the number of different blocks in the following data set. The maximum
value for n is 30. Each of the next n lines contains three integers representing the values
Trang nộp bài trực tuyến dành cho sinh viên
x i , yi and z i . tham gia môn học "Thuật toán ứng dụng" của
Viện CNTT-TT, Đại học BKHN
Input is terminated by a value of zero (0) for n.
Group website
Output
For each test case, print one line containing the case number (they are numbered sequentially
starting from 1) and the height of the tallest possible tower in the format "Case case: maximum Training 5 - Dynamic
height = height" Programming - 20201
Contest is running
Example
input Copy 9 months
1 Contestant
10 20 30
2
6 8 10
5 5 5
7
1 1 1 → Submit?
2 2 2
3 3 3
4 4 4 Language: GNU G++17 7.3.0
5 5 5
6 6 6 Choose
Choose File No file chosen
file:
7 7 7
5
31 41 59 Submit
26 53 58
97 93 23
84 62 64
33 83 27 → Your points
0
Points
output Copy A 100
Case 1: maximum height = 40 B
 Case 2: maximum height = 21 C
Case 3: maximum height = 28
Case 4: maximum height = 342 E

F 80

G
I

L
P 100

R 100
S 100

Total 480

Codeforces (c) Copyright 2010-2021 Mike Mirzayanov


The only programming contests Web 2.0 platform
Server time: Jan/13/2021 23:36:51UTC+7 (h2).
Desktop version, switch to mobile version.
Privacy Policy

Supported by

Trường ĐH Bách Khoa Hà Nội |

Thuật toán ứng dụng 0460183554HuyNQ | Logout


=> Hướng dẫn

HOME TOP CONTESTS GYM PROBLEMSET GROUPS RATING EDU API CALENDAR HELP

PROBLEMS SUBMIT CODE MY SUBMISSIONS STATUS STANDINGS CUSTOM INVOCATION

ĐH Bách Khoa Hà Nội


J. 05. WAREHOUSE Private
time limit per test: 1 second
Participant
memory limit per test: 256 megabytes
input: standard input
output: standard output

A truck is planned to arrive at some stations among N stations 1, 2, . . . , N located on a → About Group
line. Station i (i = 1, … , N ) has coordinate i and has following information

ai : amount of goods
t i : pickup time duration for taking goods

The route of the truck is a sequence of stations x 1 < x 2 <. . . < x k (


1 ≤ x j ≤ N , j = 1, … , k ). Due to technical constraints, the distance between two

consecutive stations that the truck arrives x i and x i+1 is less than or equal to D and the total
pickup time duration cannot exceed T . Find a route for the truck such that total amount of
goods picked up is maximal.
Input

Line 1: N , T , D (1 ≤ N ≤ 1000, 1 ≤ T ≤ 100, 1 ≤ D ≤ 10 )

Line 2: a1 , … , aN (1 ≤ ai ≤ 10)
Line 3: t1 , … , tN (1 ≤ ti ≤ 10)

Output
Write the total amount of goods that the truck picks up in the route.
Trang nộp bài trực tuyến dành cho sinh viên
tham gia môn học "Thuật toán ứng dụng" của
Example Viện CNTT-TT, Đại học BKHN
input Copy
Group website
6 6 2
6 8 5 10 11 6
1 2 2 3 3 2
Training 5 - Dynamic
output Copy Programming - 20201
24 Contest is running
9 months
Contestant

→ Submit?

Language: GNU G++17 7.3.0

Choose
Choose File No file chosen
file:

Submit

→ Your points
Points
A 100
B
 C
E

F 80

G
I

L
P 100

R 100
S 100

Total 480

Codeforces (c) Copyright 2010-2021 Mike Mirzayanov


The only programming contests Web 2.0 platform
Server time: Jan/13/2021 23:37:03UTC+7 (h2).
Desktop version, switch to mobile version.
Privacy Policy

Supported by

Trường ĐH Bách Khoa Hà Nội |

Thuật toán ứng dụng 0460183554HuyNQ | Logout


=> Hướng dẫn

HOME TOP CONTESTS GYM PROBLEMSET GROUPS RATING EDU API CALENDAR HELP

PROBLEMS SUBMIT CODE MY SUBMISSIONS STATUS STANDINGS CUSTOM INVOCATION

ĐH Bách Khoa Hà Nội


K. 05. RETAIL OUTLETS Private
time limit per test: 1 second
Participant
memory limit per test: 256 megabytes
input: standard input
output: standard output

A distribution company distribute goods to M retail outlets 1, 2, … , M . It has N branches → About Group
1, 2, . . . , N . Each branch i has ai salesman. The company have to assign M retail outlets

to N branches: each branch is responsible to distribute goods to some retail outlets, each
retail outlet is distributed by one branch. In order to balance among salesman, the number of
retail outlets assigned to each branch i must be positive and divisible by ai . Compute the total
number Q of ways of such assignment.

Example, N = 2, M = 20, a1 = 3, a2 = 2. There are 3 ways:

Branch 1 is assigned to 6 retail outlets, branch 2 is assigned to 14 retail outlets


Branch 1 is assigned to 12 retail outlets, branch 2 is assigned to 8 retail outlets
Branch 1 is assigned to 18 retail outlets, branch 2 is assigned to 2 retail outlets

Input

Line 1: N and M (1 ≤ N ≤ 100, 1 ≤ M ≤ 500 )


Line 2: N positive integers a1 , … , aN (1 ≤ ai ≤ 10, i = 1, … , N )

Output
Write the value Q modulo (10^9+7)
Trang nộp bài trực tuyến dành cho sinh viên
tham gia môn học "Thuật toán ứng dụng" của
Example Viện CNTT-TT, Đại học BKHN

input Copy
Group website
2 20
3 2

output Copy Training 5 - Dynamic


Programming - 20201
3
Contest is running
9 months
Contestant

→ Submit?

Language: GNU G++17 7.3.0

Choose
Choose File No file chosen
file:

Submit

→ Your points
Points
A 100
B

C
E

F 80

G
I

L
P 100

R 100
S 100

Total 480

Codeforces (c) Copyright 2010-2021 Mike Mirzayanov


The only programming contests Web 2.0 platform
Server time: Jan/13/2021 23:37:15UTC+7 (h2).
Desktop version, switch to mobile version.
Privacy Policy

Supported by

Trường ĐH Bách Khoa Hà Nội |

Thuật toán ứng dụng 0460183554HuyNQ | Logout


=> Hướng dẫn

HOME TOP CONTESTS GYM PROBLEMSET GROUPS RATING EDU API CALENDAR HELP

PROBLEMS SUBMIT CODE MY SUBMISSIONS STATUS STANDINGS CUSTOM INVOCATION

ĐH Bách Khoa Hà Nội


L. 05. DRONE PICKUP Private
time limit per test: 1 second
Participant
memory limit per test: 256 megabytes
input: standard input
output: standard output

A Drone is planned to fly from point 1 to point N in which it can stop at some points among → About Group
1, 2, … , N . These points are located on a line, point i has coordinate i. Each point i is

associated with

ci : amount of good
ai : amount of energy

When the drone stops at point i, it takes the amount ci of good and the amount ai of energy.
After that, it can fly farthest to point i + ai (it can stops at some point among
i + 1, i + 2, … , i + ai ). Due to technical constraints, the Drone can only stop at at most

K + 1 point. Compute the route (sequence of points at which the drone stops to take goods

and energy) starting from point 1 and terminating at point N such that the total amount of
goods is maximal (points 1 and N are considered as points that the Drone stop).
Input

Line 1: N and K (1 ≤ N ≤ 3000, 1 ≤ K ≤ 100 )


Line 2: N positive integers c1 , c2 , … , cN (1 ≤ ci ≤ 20, ∀i = 1, … , N )
Line 3: N positive integers a1 , a2 , … , aN (1 ≤ ai ≤ 50, ∀i = 1, … , N )

Trang nộp bài trực tuyến dành cho sinh viên


Output tham gia môn học "Thuật toán ứng dụng" của
Total amount of goods that the Drone takes during the route, or value -1 if no route exists. Viện CNTT-TT, Đại học BKHN

Example Group website

input Copy

6 3 Training 5 - Dynamic
3 1 4 2 2 2 Programming - 20201
2 3 1 1 3 1
Contest is running
output Copy

8 9 months
Contestant

→ Submit?

Language: GNU G++17 7.3.0

Choose
Choose File No file chosen
file:

Submit

→ Your points
Points
A 100
B

C
E

F 80

G
I

L
P 100

R 100
S 100

Total 480

Codeforces (c) Copyright 2010-2021 Mike Mirzayanov


The only programming contests Web 2.0 platform
Server time: Jan/13/2021 23:37:26UTC+7 (h2).
Desktop version, switch to mobile version.
Privacy Policy

Supported by

Trường ĐH Bách Khoa Hà Nội |

Thuật toán ứng dụng 0460183554HuyNQ | Logout


=> Hướng dẫn

HOME TOP CONTESTS GYM PROBLEMSET GROUPS RATING EDU API CALENDAR HELP

PROBLEMS SUBMIT CODE MY SUBMISSIONS STATUS STANDINGS CUSTOM INVOCATION

ĐH Bách Khoa Hà Nội


P. INCREASE SUBSEQ Private
time limit per test: 1 second
Participant
memory limit per test: 256 megabytes
input: standard input
output: standard output

Given a sequence of integers a1 , … , an . Compute the longest subsequence (elements are → About Group
not necessarily continous) in which elements are in an increasing orders.

Input
4
Line 1 contains an integer n (1 ≤ n ≤ 10 )
Line 2 contains n integers a1 , … , an

Output
Write the length of the longest subsequence found.

Example
input Copy

10
7 2 3 7 5 4 2 1 9 6

output Copy

Trang nộp bài trực tuyến dành cho sinh viên


tham gia môn học "Thuật toán ứng dụng" của
Viện CNTT-TT, Đại học BKHN

Group website

Training 5 - Dynamic
Programming - 20201
Contest is running
9 months
Contestant

→ Submit?

Language: GNU G++17 7.3.0

Choose
Choose File No file chosen
file:

Submit

→ Last submissions
Submission Time Verdict
101503899 Dec/17/2020 Perfect result:
15:50 100 points

→ Your points
Points

A 100
B

F 80
G

J
K

P 100
Q

R 100

S 100
Total 480

Codeforces (c) Copyright 2010-2021 Mike Mirzayanov


The only programming contests Web 2.0 platform
Server time: Jan/13/2021 23:37:36UTC+7 (h2).
Desktop version, switch to mobile version.
Privacy Policy

Supported by

Trường ĐH Bách Khoa Hà Nội |

Thuật toán ứng dụng 0460183554HuyNQ | Logout


=> Hướng dẫn

HOME TOP CONTESTS GYM PROBLEMSET GROUPS RATING EDU API CALENDAR HELP

PROBLEMS SUBMIT CODE MY SUBMISSIONS STATUS STANDINGS CUSTOM INVOCATION

ĐH Bách Khoa Hà Nội


Q. LONGEST COMMON SUBSEQUENCE Private
time limit per test: 1 second
Participant
memory limit per test: 512 megabytes
input: standard input
output: standard output

A subsequence of a given sequence S = S1 , … , Sn is obtained by removing some → About Group


elements from S . Given two sequence of integers X = (X1 , … , Xn ) and
Y = (Y 1 , … , Y m ) . Find the longest common subsequence of X and Y .

Input
4
Line 1 contains n and m (1 ≤ n, m ≤ 10 )
Line 2 contains X1 , … , Xn
Line 3 contains Y1 , … , Ym

Output
Write the length of the longest subsequence of the given sequences

Example
input Copy

7 10
3 7 2 5 1 4 9
4 3 2 3 6 1 5 4 9 7

output Copy
Trang nộp bài trực tuyến dành cho sinh viên
5 tham gia môn học "Thuật toán ứng dụng" của
Viện CNTT-TT, Đại học BKHN

Group website

Training 5 - Dynamic
Programming - 20201
Contest is running
9 months
Contestant

→ Submit?

Language: GNU G++17 7.3.0

Choose
Choose File No file chosen
file:

Submit

→ Your points
Points
A 100
B

C
E

F 80

G
I

L
P 100

R 100
S 100

Total 480

Codeforces (c) Copyright 2010-2021 Mike Mirzayanov


The only programming contests Web 2.0 platform
Server time: Jan/13/2021 23:37:38UTC+7 (h2).
Desktop version, switch to mobile version.
Privacy Policy

Supported by

Trường ĐH Bách Khoa Hà Nội |

Thuật toán ứng dụng 0460183554HuyNQ | Logout


=> Hướng dẫn

HOME TOP CONTESTS GYM PROBLEMSET GROUPS RATING EDU API CALENDAR HELP

PROBLEMS SUBMIT CODE MY SUBMISSIONS STATUS STANDINGS CUSTOM INVOCATION

ĐH Bách Khoa Hà Nội


R. MAX SUBSEQUENCE Private
time limit per test: 1 second
Participant
memory limit per test: 256 megabytes
input: standard input
output: standard output

Given an integers sequence a = (a1 , a2 , … , an ). A subsequence of a is defined to be → About Group


ai , ai+1 , … , aj . The weight of a subsequence is the sum of its elements. Find the

subsequence having the highest weight.

Input
6
Line 1 contains n (1 ≤ n ≤ 10 )
Line 2 contains a1 , … , an (−500 ≤ ai ≤ 500 )

Output
Write the weight of the highest subsequence found.

Example
input Copy

10
3 -1 -3 5 2 5 0 -1 5 4

output Copy

20
Trang nộp bài trực tuyến dành cho sinh viên
tham gia môn học "Thuật toán ứng dụng" của
Viện CNTT-TT, Đại học BKHN

Group website

Training 5 - Dynamic
Programming - 20201
Contest is running
9 months
Contestant

→ Submit?

Language: GNU G++17 7.3.0

Choose
Choose File No file chosen
file:

Submit

→ Last submissions
Submission Time Verdict
101501383 Dec/17/2020 Perfect result:
15:17 100 points

→ Your points
Points

A 100
B

F 80
G

J
K

P 100
Q

R 100

S 100
Total 480

Codeforces (c) Copyright 2010-2021 Mike Mirzayanov


The only programming contests Web 2.0 platform
Server time: Jan/13/2021 23:37:39UTC+7 (h2).
Desktop version, switch to mobile version.
Privacy Policy

Supported by

Trường ĐH Bách Khoa Hà Nội |

Thuật toán ứng dụng 0460183554HuyNQ | Logout


=> Hướng dẫn

HOME TOP CONTESTS GYM PROBLEMSET GROUPS RATING EDU API CALENDAR HELP

PROBLEMS SUBMIT CODE MY SUBMISSIONS STATUS STANDINGS CUSTOM INVOCATION

ĐH Bách Khoa Hà Nội


S. RMQ Private
time limit per test: 1 second
Participant
memory limit per test: 256 megabytes
input: standard input
output: standard output

Given a sequence of n integers a0 , … , an−1 . We denote rmq (i, j) the minimum element → About Group
of the sequence ai , ai+1 , … , aj . Given m pairs (i1 , j 1 ), … , (im , j m ), compute the
m
sum Q = ∑
k=1
rmq(ik , j k )

Input
6
Line 1: n (1 ≤ n ≤ 10 )
Line 2: a0 , … , an−1 (1 ≤ ai ≤ 10
6
)
line 3: m (1 ≤ m ≤ 10 ) 6

Line k + 3 (k = 1, … , m ): ik , j k (0 ≤ ik < j k < n )

Output
Write the value Q

Scoring
50% tests with 1 ≤ n ≤ 5000

Example
input Copy
Trang nộp bài trực tuyến dành cho sinh viên
16 tham gia môn học "Thuật toán ứng dụng" của
2 4 6 1 6 8 7 3 3 5 8 9 1 2 6 4 Viện CNTT-TT, Đại học BKHN
4
1 5 Group website
0 9
1 15
6 10
Training 5 - Dynamic
output Copy Programming - 20201
6 Contest is running
9 months
Contestant

→ Submit?

Language: GNU G++17 7.3.0

Choose
Choose File No file chosen
file:

Submit

→ Last submissions
Submission Time Verdict
100844644 Dec/10/2020 Perfect result:
17:58 100 points

Dec/10/2020 Wrong answer on
100844323
17:54 test 1

Dec/10/2020 Partial result: 10


100843992
17:50 points
Dec/10/2020 Partial result: 10
100843836
17:48 points

Memory limit
Dec/10/2020
100843690 exceeded on test
17:46
1

Dec/10/2020 Partial result: 10


100843409
17:42 points
Dec/10/2020 Wrong answer on
100843275
17:41 test 1

→ Your points
Points

A 100
B

E
F 80

J
K
L

P 100
Q

R 100
S 100
Total 480

Codeforces (c) Copyright 2010-2021 Mike Mirzayanov


The only programming contests Web 2.0 platform
Server time: Jan/13/2021 23:37:40UTC+7 (h2).
Desktop version, switch to mobile version.
Privacy Policy

Supported by

You might also like