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

歡迎訪問 生活随笔!

生活随笔

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

编程问答

ACM/ICPC 2018亚洲区预选赛北京赛站网络赛 80 Days(双向队列+尺取法)

發布時間:2025/3/15 编程问答 12 豆豆
生活随笔 收集整理的這篇文章主要介紹了 ACM/ICPC 2018亚洲区预选赛北京赛站网络赛 80 Days(双向队列+尺取法) 小編覺得挺不錯的,現在分享給大家,幫大家做個參考.

#1831 : 80 Days

時間限制:1000ms

單點時限:1000ms

內存限制:256MB

描述

80 Days is an interesting game based on Jules Verne's science fiction "Around the World in Eighty Days".?In this game, you have to manage the limited money and time.

Now we simplified the game as below:

There are?n?cities on a circle around the world which are numbered from 1 to?n?by their order on the circle. When you reach the city?i?at the first time, you will get?ai?dollars (ai?can even be negative), and if you want to go to the next city on the circle, you should pay?bi?dollars. At the beginning you have?c?dollars.

The goal of this game is to choose a city as start point, then go along the circle and visit all the city once, and finally return to the start point. During the trip, the money you have must be no less than zero.

Here comes a question: to complete the trip, which city will you choose to be the start city?

If there are multiple answers, please output the one with the smallest number.

輸入

The first line of the input is an integer?T?(T?≤ 100), the number of test cases.

For each test case, the first line contains two integers?n?and?c?(1 ≤?n?≤ 106, 0 ≤?c?≤ 109). ?The second line contains?n?integers?a1, …, an??(-109?≤?ai?≤ 109), and the third line contains?n?integers?b1, …, bn?(0 ≤?bi?≤ 109).

It's guaranteed that the sum of?n?of all test cases is less than 106

輸出

For each test case, output the start city you should choose.

提示

For test case 1, both city 2 and 3 could be chosen as start point, 2 has smaller number. But if you start at city 1, you can't go anywhere.

For test case 2, start from which city seems doesn't matter, you just don't have enough money to complete a trip.

樣例輸入

2 3 0 3 4 5 5 4 3 3 100 -3 -4 -5 30 40 50

樣例輸出

2 -1

直接模擬肯定會TLE,有尺取法,可以減少很多的枚舉

#include<bits/stdc++.h> using namespace std;#define e exp(1) #define pi acos(-1) #define mod 998244353 #define inf 0x3f3f3f3f #define ll long long #define ull unsigned long long #define mem(a,b) memset(a,b,sizeof(a)) int gcd(int a,int b){return b?gcd(b,a%b):a;}const int maxn=2e6+5; int n; ll c,a[maxn],b[maxn],s[maxn]; deque<int> q; int main() {int T;scanf("%d",&T);while(T--){scanf("%d%lld",&n,&c);for(int i=1; i<=n; i++)scanf("%lld",&a[i]);for(int i=1; i<=n; i++)scanf("%lld",&b[i]);for(int i=n+1; i<=2*n; i++)a[i]=a[i-n],b[i]=b[i-n];while(q.size())q.pop_back();int flag=0;for(int i=1; i<=2*n; i++){if(c+a[i]-b[i]>=0){c+=a[i]-b[i];q.push_back(i);if(q.size()>=n){flag=1;printf("%d\n",q.front());break;}}else {while(c+a[i]-b[i]<0&&q.size()){c-=a[q.front()]-b[q.front()];q.pop_front();}if(c+a[i]-b[i]>=0){c+=a[i]-b[i];q.push_back(i);if(q.size()>=n){flag=1;printf("%d\n",q.front());break;}}}}if(flag==0)puts("-1");}return 0; }

?

總結

以上是生活随笔為你收集整理的ACM/ICPC 2018亚洲区预选赛北京赛站网络赛 80 Days(双向队列+尺取法)的全部內容,希望文章能夠幫你解決所遇到的問題。

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

主站蜘蛛池模板: 免费看日产一区二区三区 | 牛人盗摄一区二区三区视频 | 日韩首页| 国产丝袜一区二区三区 | 亚洲熟妇一区二区三区 | 日韩偷拍一区 | 高潮一区二区三区 | 亚洲AV成人精品 | 亚洲爽爽爽 | 亚洲一本二本 | 超碰人人人 | 91丨porny丨在线中文 | 少妇精品一区二区三区 | 97视频在线播放 | 国产精品免费视频观看 | 国产成人精品视频在线 | 亚洲高清av在线 | 制服丝袜中文字幕在线 | 成人国产免费 | 三点尽露的大尺度国产 | 青青青国产在线 | av激情在线观看 | 色天天干| 97香蕉久久夜色精品国产 | 日本免费在线观看 | 一眉道姑 | 人妻 校园 激情 另类 | 亚洲精品视频免费看 | 国产日韩欧美中文 | 美女被男生免费视频 | 在线免费观看视频网站 | 性生交大片免费看l | 国产精品v欧美精品v日韩 | 交专区videossex另类 | 亚洲系列中文字幕 | 一区二区欧美日韩 | 精品三级视频 | 久久99久久98精品免观看软件 | 麻豆成人91精品二区三区 | 成人av影院在线观看 | 超碰97国产精品人人cao | 国产成人av影院 | 丰满的女人性猛交 | 我爱我色成人网 | 欧美另类人妖 | 日本网站在线免费观看 | 亚洲一区二区av | 四虎1515hh.com | 草莓视频在线观看18 | 女人十八毛片嫩草av | 日韩成人不卡 | 欧美永久 | 女人下面流白浆的视频 | 麻豆av网站 | 免费成人看片 | 国产最新视频 | 自拍偷拍av| 极品美女销魂一区二区三区 | 中文字幕在线观看91 | 国产精品久久不卡 | 日韩激情网址 | 中国一级片黄色一级片黄 | 色播久久 | 深夜网站在线观看 | 婷婷综合国产 | 日本国产中文字幕 | 一区二区日韩精品 | 樱桃香蕉视频 | 免费a在线观看播放 | 这里精品| 朝桐光av一区二区三区 | 亚洲激情久久久 | 免费毛片网 | 欧美中文字幕在线 | 欧美日韩一区视频 | 可以在线观看av的网站 | 欧洲女女同videos | 少妇人妻精品一区二区三区 | 黄色av软件| 动漫3d精品一区二区三区乱码 | 和黑帮大佬的365 | 天天躁夜夜躁av天天爽 | 制服诱惑一区二区 | 色综合久久88色综合天天 | 亚洲一级在线观看 | 精品午夜一区二区 | 日本三级吹潮 | 男男免费视频 | 欧美xxxbbb| 成人欧美一区二区三区黑人免费 | 中文字幕乱码无码人妻系列蜜桃 | 久草最新视频 | 亚洲一区二区自拍偷拍 | www天堂在线| 一卡二卡精品 | 久久人人爽人人 | av最新地址 | 久久久久久久久久久久电影 | 午夜精品福利视频 |