1. 正解能得到全對的分數(得2 分)
2. 奧步能拿到半對(得1 分)
3. 放棄的話當然就沒分囉(0 分)
。試問:在時間T 內,用最佳的答題方式,最多可以拿幾分?
輸入說明:
輸入檔第一行說明有幾組測試資料,第二行有兩個整數n 和T,分別代表有幾題,以及總作答時間。接下來n 行每行有兩個整數Ci 和Hi,代表第i 題寫正解需要時間Ci,寫奧步需要時間Hi。其中:- 題目總數n≤100000
- 答題所需時間1≤Hi,Ci≤1000000
- 總作答時間0<, T≤1000000000
輸出說明:
每個測試範例請輸出一個整數,代表最大得分。
輸入範例:
25 12
4 3
6 2
5 3
4 3
5 2
4 10
5 3
6 5
3 1
4 3
輸出範例:
6
5
Dim Ci(), Hi(), cost(), core() As Double
回覆刪除Private Sub Form_Load()
Me.Hide
Open App.Path & "\in.txt" For Input As #1
Open App.Path & "\out.txt" For Output As #2
Input #1, mycount
For i = 1 To mycount
Input #1, question, timee
ReDim Ci(question), Hi(question), cost(question), core(question)
For ii = 1 To question
Input #1, temp1, temp2
bestime = bestime + temp1
Ci(ii) = 2 / temp1: Hi(ii) = 1 / temp2
If Ci(ii) > Hi(ii) Then cost(ii) = temp1: core(ii) = 2
If Ci(ii) < Hi(ii) Then cost(ii) = temp2: core(ii) = 1
Next
If bestime <= timee Then
Print #2, question * 2
bestime = 0
Else
For iii = 1 To question
totaltime = cost(iii)
coree = core(iii)
For iiii = 1 To question
If totaltime + cost(iiii) <= timee Then
totaltime = totaltime + cost(iiii)
coree = coree + core(iiii)
If coree > Max Then Max = coree
End If
Next
totaltime = 0
coree = 0
Next
Print #2, Max
Max = 0: bestime = 0
End If
Next
Close #2
Close #1
End
End Sub