当前位置:网站首页>【CF#223 (Div. 2)】A. Sereja and Dima
【CF#223 (Div. 2)】A. Sereja and Dima
2022-06-11 07:11:00 【percation】
The question : Put the cards in a row on the table ,S and D Two candidate cards ( Only the leftmost and rightmost cards can be selected ), To maximize their total points .
The cards on the table are gone , Then the game is over .
S For the first time
Ideas : simulation , Double pointer , greedy .
Locate the left and right ends of the array , The double pointer moves to the middle , Know that double pointers point to the same element , At the same time, judge whose turn it is to touch the cards .
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const int N = 1e5 + 10;
int n,t,m;
int a[N],b[N],c[N];
bool vis[N];
int main(){
cin >> n;
int u = n;
int s = 0, d = 0;
for(int i = 0; i < n; i++){
cin >> a[i];
}
int i = 0, j = n - 1, flag = 1;
while(i != j){
if(a[i] > a[j]){
if(flag == 1){
s += a[i];
flag = 0;
}
else{
d += a[i];
flag = 1;
}
i++;
}
else{
if(flag == 1){
s += a[j];
flag = 0;
}
else{
d += a[j];
flag = 1;
}
j--;
}
u--;
}
if(flag == 1){
s += a[i];
}
else{
d += a[i];
}
cout << s << " " << d << endl;
return 0;
}
边栏推荐
- Object. Specific implementation and difference between create() and new
- Outer margin collapse
- VTK vtkplane and vtkcutter use
- Shell脚本之启动Nacos服务端
- 213. house raiding II
- Grayscale publishing through ingress
- Senior openstacker - Bloomberg, vexxhost upgraded to gold member of openinfra Foundation
- [MATLAB image encryption and decryption] chaotic sequence image encryption and decryption (including correlation test) [including GUI source code 1862]
- P3172 [cqoi2015] data selection (Mobius inversion + Du Jiao sieve)
- Completed in May, 22
猜你喜欢

Difference between byte and bit

1266_FreeRTOS调度器启动代码实现分析

教育专家王中泽老师:家庭教育重在自己成长

webserver

教育专家王中泽老师一招解决学生问题

【LeetCode】-- 17. Letter combination of telephone number

教育专家王中泽老师多年经验分享:家庭教育不是附庸品

Analysis of key points and difficulties of ES6 promise source code

Web API、DOM
![[deploy private warehouse based on harbor] 4 push image to harbor](/img/af/8e28b229d94f3e6eab02308b69dc74.jpg)
[deploy private warehouse based on harbor] 4 push image to harbor
随机推荐
This comprehensive understanding
品牌定位个性六种形态及结论的重大意义
Start the Nacos server of shell script
Adventure of small X
1734. arrangement after decoding XOR
Shuttle container component
[MATLAB image encryption and decryption] chaotic sequence image encryption and decryption (including correlation test) [including GUI source code 1862]
Stack -- one of two common linear structures of linear structure
Shangtang technology has actively resumed work and will vigorously invest in the capacity and deployment of the digital sentry
Interview question 17.08 Circus tower
1266_ Implementation analysis of FreeRTOS scheduler startup code
[deploy private warehouse based on harbor] 3 deploy harbor
Drawing with qpainter
Oracle pl/sql these query results cannot be updated. Please include ROWID or use Select For update
教育专家王中泽老师多年经验分享:家庭教育不是附庸品
[deploy private warehouse based on harbor] 2 machine preparation
资深OpenStacker - 彭博、Vexxhost升级为OpenInfra基金会黄金成员
Education expert Mr. wangzhongze: family education focuses on self growth
[matlab printed character recognition] OCR printed letter + number recognition [including source code 1861]
matplotlib的cmap