是我没理解题意?用一个deque不能解决问题? #include<iostream> #include<deque> using namespace std; int MaxValue(deque<int> queue) { int sum=0; int price=1; while(!queue.empty()) { int start=queue.front(); int end=queue.back(); if(start<end) { queue.pop_front(); sum+=price*start; } else { queue.pop_back(); sum+=price*end; } price++; } return sum; } int main() { int num; cin>>num; int i=0; int tmp; deque<int> queue; while(i<num) { cin>>tmp; queue.push_back(tmp); i++; } int ret=MaxValue(queue); cout<<ret<<endl; //system("pause"); return 0; }
点赞 3

相关推荐

owwhy:难,技术栈在嵌入式这块显得非常浅,并且简历有大问题。教育经历浓缩成两行就行了,写什么主修课程,说的不好听这块没人在意,自我评价删了,项目写详细点,最终简历缩成一页。相关技能怎么说呢,有点差了,还写成这么多行
投了多少份简历才上岸
点赞 评论 收藏
分享
牛客网
牛客网在线编程
牛客网题解
牛客企业服务