当前位置:网站首页>【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;
}
边栏推荐
- [matlab printed character recognition] OCR printed letter + number recognition [including source code 1861]
- CMAP of Matplotlib
- Comparison of DOM tags of wechat applet development (native and uniapp)
- MS office level II wrong question record [8]
- 微信小程序开发(原生和uniapp)DOM标签对比介绍
- [advanced concurrency] - thread pool summary
- 商汤科技积极复工,将大力投入数字哨兵的产能和部署
- Menu double linkage effect in uniapp
- Transformer Tracking
- The gap between the parent box and the child box
猜你喜欢

Education expert Mr. wangzhongze: family education focuses on self growth

First day of database

The difference between arrow function and ordinary function

Detailed explanation of mutationobserver

No response from win10 explorer when dragging files

Senior openstacker - Bloomberg, vexxhost upgraded to gold member of openinfra Foundation

Leetcode hot topic 100 topic 21-25 solution

webserver

Installation de SQL Server 2008 (avec mot de passe), création d'une base de données, test de projet de formulaire C

byte和bit的区别
随机推荐
1734. arrangement after decoding XOR
matplotlib的cmap
VTK vtkplane and vtkcutter use
1269. number of options left in place
Library management system 2- demand analysis
Shuttle container component
Leetcode-647. Palindromic Substrings
saltstack部署lnmp
webserver
Dynamically change the direction of this
Menu double linkage effect in uniapp
Reconstruction and preheating of linked list information management system (2) how to write the basic logic using linear discontinuous structure?
Method to determine whether it is an array
1266_FreeRTOS调度器启动代码实现分析
Shutter restraint container assembly
[并发进阶]——线程池总结
Interview question 17.08 Circus tower
资深OpenStacker - 彭博、Vexxhost升级为OpenInfra基金会黄金成员
Heartless sword Chinese English bilingual poem 001 Love
Flutter 内外边距