Skip to content

Instantly share code, notes, and snippets.

@blutarche
Created May 30, 2019 18:47
Show Gist options
  • Save blutarche/3373b133643a832d50146328b618d5f7 to your computer and use it in GitHub Desktop.
Save blutarche/3373b133643a832d50146328b618d5f7 to your computer and use it in GitHub Desktop.
#include"cstdio"
#include"iostream"
using namespace std;
# define N 1001
int day[N][N] = {0}, minute[N][N] = {0};
void print(int n) {
for (int i = 0; i <= n; i++) {
for (int j = 0; j <= n; j++) {
cout << day[i][j] << "," << minute[i][j] << " ";
}
cout << endl;
}
}
main() {
int m, n;
cin >> m;
cin >> n;
int j[N], k[N];
j[0] = 0;
for (int i = 1; i <= n; i++) {
cin >> j[i];
}
k[0] = 0;
for (int i = 1; i <= n; i++) {
cin >> k[i];
}
for (int a = 0; a <= n; a++) {
int jj = j[a];
for (int b = 0; b <= n; b++) {
if (a == 0 && b == 0) continue;
int kk = k[b];
// cout << a << "," << b << " :: j=" << jj << ",k=" << kk << endl;
int minuteLeft = 1000000;
int dayLeft = 1000000;
if (b > 0) {
minuteLeft = minute[a][b -1] + kk;
dayLeft = day[a][b-1];
if (minuteLeft > m) {
dayLeft += 1;
minuteLeft = kk;
}
}
int minuteUp = 1000000;
int dayUp = 1000000;
if (a > 0) {
minuteUp = minute[a - 1][b] + jj;
dayUp = day[a-1][b];
if (minuteUp > m) {
dayUp += 1;
minuteUp = jj;
}
}
if (dayLeft < dayUp || (dayLeft == dayUp && minuteLeft < minuteUp)) {
day[a][b] = dayLeft;
minute[a][b] = minuteLeft;
} else {
day[a][b] = dayUp;
minute[a][b] = minuteUp;
}
// print(n);
// cout << ":: " << day[a][b] << "," << minute[a][b] << endl;
}
}
cout << day[n][n] + 1 << endl;
cout << minute[n][n] << endl;
return 0;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment