This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#include <stdio.h>
int N, M, c[100] = { 0 }, m[100] = { 0 }, deque[100] = { 0 }, front = 0, rear = 0, uber[100] = { 0 };
bool seg[100][100] = { 0 };
void push(int elm){
deque[rear++] = elm; return;
}
int pop(){
++front; return deque[front - 1];
}
int cost(int remmem){
int first, used, unused, move=0;
bool check[100] = { 0 };
if (remmem <= 0) return 0;
if (front == rear) return 10001;
first = pop();
for (int i = 0; i < N; ++i){
if (seg[first][i]){
check[i] = 1;
seg[first][i] = 0;
--uber[i];
if (uber[i] == 0){
push(i);
++move;
}
}
}
unused = cost(remmem);
used = c[first]+cost(remmem - m[first]);
--front;
rear -= move;
for (int i = 1; i<N; ++i){
if (check[i]){
seg[first][i] = 1;
++uber[i];
}
}
if (used > unused) return unused;
return used;
}
int main(){
scanf("%d %d", &N, &M);
for (int i = 0; i < N; ++i){
scanf("%d", &m[i]);
}
for (int i = 0; i < N; ++i){
scanf("%d", &c[i]);
for (int j = 0; j < i; ++j){
if ((c[i] <= c[j]) && (m[i] >= m[j])){
seg[i][j] = 1;
++uber[j];
}
else if ((c[i] >= c[j]) && (m[i] <= m[j])){
seg[j][i] = 1;
++uber[i];
}
}
}
for (int i = 0; i < N; ++i){
if (uber[i] == 0) push(i);
}
printf("%d\n", cost(M));
return 0;
}
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |