爱奇艺编程题:空中旅行

题目:https://www.nowcoder.com/practice/cc929a2ed85f4f49b834e6e301fba77b?tpId=90&tqId=30792&tPage=1&rp=1&ru=/ta/2018test&qru=/ta/2018test/question-ranking

#include

using namespace std;

int func(vector &num,int s){

if(num[0] > s)

return 0;

int n = num.size();

vector dp(n + 1,0);

dp[1] =  num[0];

for(auto i = 2;i

dp[i] = dp[i-1] + num[i-1];

for(auto i = 1;i < n+1;++i){

if(dp[i] <= s && dp[i+1] > s)

return i;

}

return n;

}

int main(){

int n,s;

while(cin >> n >> s){

vector num(n);

for(auto i = 0;i < n;++i)

cin>>num[i];

cout<

}

return 0;

}

你可能感兴趣的:(爱奇艺编程题:空中旅行)