-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
1 changed file
with
37 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
import java.io.BufferedReader; | ||
import java.io.IOException; | ||
import java.io.InputStreamReader; | ||
import java.util.Arrays; | ||
import java.util.StringTokenizer; | ||
|
||
public class Main { | ||
|
||
public static void main(String[] args) throws IOException { | ||
|
||
BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); | ||
StringTokenizer st = new StringTokenizer(br.readLine()); | ||
int c = Integer.parseInt(st.nextToken()); | ||
int n = Integer.parseInt(st.nextToken()); | ||
|
||
int[] dp = new int[c + 100]; | ||
Arrays.fill(dp, Integer.MAX_VALUE); | ||
dp[0] = 0; | ||
|
||
for (int i = 0; i < n; i++) { | ||
st = new StringTokenizer(br.readLine()); | ||
int cost = Integer.parseInt(st.nextToken()); | ||
int customer = Integer.parseInt(st.nextToken()); | ||
|
||
for (int j = customer; j < c + 100; j++) { | ||
if (dp[j - customer] != Integer.MAX_VALUE) | ||
dp[j] = Math.min(dp[j], cost + dp[j - customer]); | ||
} | ||
} | ||
|
||
int answer = Integer.MAX_VALUE; | ||
for (int i = c; i < c + 100; i++) { | ||
answer = Math.min(answer, dp[i]); | ||
} | ||
System.out.println(answer); | ||
} | ||
} |