日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 > 编程资源 > 编程问答 >内容正文

编程问答

【CodeForces - 632B】Alice, Bob, Two Teams (预处理,思维,前缀和后缀和)

發布時間:2023/12/10 编程问答 22 豆豆
生活随笔 收集整理的這篇文章主要介紹了 【CodeForces - 632B】Alice, Bob, Two Teams (预处理,思维,前缀和后缀和) 小編覺得挺不錯的,現在分享給大家,幫大家做個參考.

題干:

Alice and Bob are playing a game. The game involves splitting up game pieces into two teams. There are?n?pieces, and the?i-th piece has a strength?pi.

The way to split up game pieces is split into several steps:

  • First, Alice will split the pieces into two different groups?A?and?B. This can be seen as writing the assignment of teams of a piece in an?n?character string, where each character is?A?or?B.
  • Bob will then choose an arbitrary prefix or suffix of the string, and flip each character in that suffix (i.e. change?A?to?B?and?B?to?A). He can do this step at most once.
  • Alice will get all the pieces marked?A?and Bob will get all the pieces marked?B.
  • The strength of a player is then the sum of strengths of the pieces in the group.

    Given Alice's initial split into two teams, help Bob determine an optimal strategy. Return the maximum strength he can achieve.

    Input

    The first line contains integer?n?(1?≤?n?≤?5·105) — the number of game pieces.

    The second line contains?n?integers?pi?(1?≤?pi?≤?109) — the strength of the?i-th piece.

    The third line contains?n?characters?A?or?B?— the assignment of teams after the first step (after Alice's step).

    Output

    Print the only integer?a?— the maximum strength Bob can achieve.

    Examples

    Input

    5 1 2 3 4 5 ABABA

    Output

    11

    Input

    5 1 2 3 4 5 AAAAA

    Output

    15

    Input

    1 1 B

    Output

    1

    Note

    In the first sample Bob should flip the suffix of length one.

    In the second sample Bob should flip the prefix or the suffix (here it is the same) of length?5.

    In the third sample Bob should do nothing.

    題目大意:

    ? ? ?A和B兩個人玩游戲,給n個數,每個數對應一個 ' A ' 或 ' B ' , 現在B玩家可以選一個前綴或者一個后綴,把A變B,B變A,操作結束后,B玩家可以取走所有標號為 ' B?' 的數字,問B玩家可以取到的數字之和最大是多少??

    解題報告:

    ? ? ?看題目名稱,猜是博弈?然而讓你失望了,這題和A沒有任何卵關系,,,先預處理出前綴A和B,后綴A和B,這四個數組。然后枚舉每一個元素,維護翻這一位或者不翻這一位的最大值maxx,并且維護和ans的最大值,輸出ans即可。

    AC代碼:

    #include<bits/stdc++.h> #define ll long long using namespace std; const int MAX = 5e5 + 5; ll val[MAX]; ll a[MAX],b[MAX],A[MAX],B[MAX]; ll ans,maxx; char s[MAX]; int main() {int n;cin>>n;for(int i = 1; i<=n; i++) scanf("%lld",val+i);cin>>s+1;//prefix預處理 for(int i = 1; i<=n; i++) {if(s[i] == 'A') {a[i] = a[i-1] + val[i];b[i] = b[i-1];}else {a[i] = a[i-1];b[i] = b[i-1] + val[i];}}//suffix預處理for(int i = n; i>=1; i--) {if(s[i] == 'A') {A[i] = A[i+1] + val[i];B[i] = B[i+1];}else {A[i] = A[i+1];B[i] = B[i+1] + val[i];}} for(int i = 1; i<=n; i++) {maxx = max(b[i]+B[i+1],a[i] + B[i+1]);ans = max(ans,maxx);}for(int i = n; i>=1; i--) {maxx = max(b[i] + B[i+1],b[i] + A[i+1]);ans = max(ans,maxx);}printf("%lld\n",ans);return 0 ; }

    ?

    總結

    以上是生活随笔為你收集整理的【CodeForces - 632B】Alice, Bob, Two Teams (预处理,思维,前缀和后缀和)的全部內容,希望文章能夠幫你解決所遇到的問題。

    如果覺得生活随笔網站內容還不錯,歡迎將生活随笔推薦給好友。

    主站蜘蛛池模板: 91精品国产高清一区二区三区蜜臀 | 乱色欧美 | 欧美日韩xxxx | av不卡中文字幕 | 91极品视频| 色婷婷一区二区 | 国产福利精品一区 | 国产日产亚洲精品 | 在线观看网页视频 | 91精品视频网 | 五月婷在线 | 日本一区视频在线 | 久爱视频在线观看 | 在线天堂中文字幕 | 免费亚洲婷婷 | wwwxxx日本| 成人亚洲一区 | 日本大尺度做爰呻吟舌吻 | 精品视频成人 | 国产91视频在线观看 | 午夜xxx | 91蝌蚪91密月 | 老熟妇高潮一区二区高清视频 | 亚洲精品一区二区在线观看 | 一区二区三区四区中文字幕 | 激情开心成人网 | 国产精品美女久久久久 | 久久人人插 | 精品人妻一区二区三区麻豆91 | 国产精品久久久久91 | 国产三级一区二区三区 | 亚洲视频精选 | 天天色天天爽 | 干美女少妇 | 国产亚洲欧美一区二区三区 | 午夜看片福利 | 麻豆91精品 | 欧美视频一 | 欧美国产综合视频 | 男生坤坤放进女生坤坤里 | 波多野结衣 一区 | 天天看片天天操 | 强公把我次次高潮hd | 成人欧美一区二区三区在线观看 | 婷婷色站| 高清日韩欧美 | 91国产丝袜在线播放 | 成人深夜福利 | 成人精品一区二区 | 2019天天操| 办公室荡乳欲伦交换bd电影 | 日韩亚洲视频在线观看 | 男女午夜啪啪 | 久久99精品久久久久久园产越南 | 国产视频一区二区三区在线观看 | 这里只有精品免费视频 | 丰满人妻一区二区三区无码av | 性欧美大战久久久久久久 | 国产精品21p | 国产1区在线观看 | 超碰男人| 高清二区 | 国精无码欧精品亚洲一区蜜桃 | 男生插女生视频在线观看 | 污污的视频网站在线观看 | 秋霞影院午夜丰满少妇在线视频 | 精品少妇一区二区三区在线观看 | 久久久久中文 | 天堂av2024| 亚洲av女人18毛片水真多 | 日本后进式猛烈xx00动态图 | 中文字幕一区二区三区乱码人妻 | 一级片视频播放 | 国产毛片3| 国产在线观看xxx | 人人舔人人 | 日日射日日干 | 亚洲成人午夜在线 | 一区二区福利电影 | 肉嫁高柳家 高清 | 毛片基地免费观看 | 538精品在线视频 | 亚洲精品天天 | 日批免费在线观看 | 清清草在线视频 | 不卡视频在线观看免费 | www.天天操 | 黄网在线免费看 | 亚洲天堂中文在线 | 2018中文字幕在线观看 | 中国av毛片 | 久久精品视频偷拍 | 国产一区二区三区免费 | 51自拍视频| 日日夜夜爱爱 | 人人干人人看 | www.17c.com喷水少妇| 午夜高清 | 自拍偷拍亚洲图片 |