CF1200B
CF1200B
解法:
贪心。当在第i列时,尽可能多的取走第i列的木块使得袋子里的木块尽可能多
CODE:
#include<iostream>
#include<cstdio>
#include<cstring>
#include<algorithm>
using namespace std;
const int N = 1e3 + 5;
int n,m,k,T,h[N];
int main() {
scanf("%d",&T);
while(T--) {
scanf("%d%d%d",&n,&m,&k);
for(int i = 1 ; i <= n ; i++)
scanf("%d",&h[i]);
if (n == 1) {
puts("YES");
continue;
}
int pos = 1;
for(int i = 2 ; i <= n ; i++) {
if(h[pos] > h[i]) {
int t = h[pos] - h[i] + k;
if (t > h[pos])
t = h[pos];
m += t;
pos++;
} else if (h[i] - h[pos] <= k) {
int t = k - h[i] + h[pos];
if (t > h[pos])
t = h[pos];
m += t;
pos++;
} else if (h[i] - h[pos] <= k + m) {
m -= h[i] - h[pos] - k;
pos++;
} else {
puts("NO");
break;
}
}
if (pos == n) puts("YES");
}
//system("pause");
return 0;
}
有些路你和某人一起走,就长得离谱,你和另外一些人走,就短得让人舍不得迈开脚步。