-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathfish.cpp
More file actions
39 lines (37 loc) · 1.01 KB
/
fish.cpp
File metadata and controls
39 lines (37 loc) · 1.01 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
// incorrect version
#include <cstdio>
#include <iostream>
using namespace std;
unsigned long long fh[10001][1000] = {0};
int used[10001][1000] = {0};
int df[1000] = {0};
int val[1000] = {0};
int main()
{
int i,j,k,T,N,K,add,loop;
scanf("%d", &T);
while(T--){
scanf("%d %d", &N, &K);
for(i=0;i<N;i++) scanf("%d %d", &val[i], &df[i]);
// base case N = 0
for(i=1;i<=val[0]/df[0]+1;i++){
fh[i][0] = fh[i-1][0] + val[0] - df[0]*used[i-1][0];
used[i][0] = i;
}
for(i=1;i<=K;i++){
for(j=1;j<N;j++){
add = val[j] - df[j]*used[i-1][j];
if(add<0) add = 0;
if(fh[i-1][j]+add>fh[i-1][j-1] && i>j){
fh[i][j] = fh[i-1][j]+add;
used[i][j] = used[i-1][j] + 1;
}else{
fh[i][j] = fh[i-1][j-1];
}
if(j>=i) break;
}
}
printf("%llu\n", fh[K][N-1]);
}
return 0;
}