日韩性视频-久久久蜜桃-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| 免费久久久久久 | 在线中文字幕日韩 | 亚洲av色一区二区三区精品 | 欧美一级性生活视频 | 久久精品日| 久久精品美乳 | 国产在成人精品线拍偷自揄拍 | 国产伦理一区 | 97久久久久久久久久 | 亚洲天堂一区二区在线观看 | 日韩一区二区高清视频 | 男男全肉变态重口高h | 男人操女人逼逼视频 | 奴色虐av一区二区三区 | 91麻豆精品一区二区三区 | 打开免费观看视频在线 | 色婷婷av一区二区三 | 狠狠91| 日韩一区二区免费视频 | 久久久久99精品成人片毛片 | 国产精品1区2区3区4区 | 日本不卡高清视频 | 亚洲第一视频网站 | 国内成人综合 | 亚洲国产成人精品女人久久久 | 国模无码视频一区 | 草草影院一区二区三区 | 久久人人爽人人爽人人 | 91精品免费在线 | 美女扒开内裤让男人桶 | 欧美xxxxav| 黄视频在线观看免费 | 午夜一区在线 | 99re在线观看 | 亚洲精选在线 | 国产乱人伦精品一区二区 | 亚洲日本成人在线观看 | 亚洲精品久久久久久久久 | 日韩激情av | 国产伦精品一区二区三区高清版禁 | 成人自拍网站 | 亚洲精品久久久久久久蜜桃 | 亚洲清纯国产 | 国产成人精品白浆久久69 | 久久国产夫妻 | 综合免费视频 | 91在线精品播放 | 国产精品传媒在线观看 | 福利视频免费看 | 亚洲成人福利在线 | 久久国产精品国语对白 | 黄色一级图片 | 国产二区三区 | 青青艹在线视频 | 深夜在线网站 | www.香蕉视频.com| 美女黄色片网站 | 91精品国产aⅴ一区二区 | 精品国产大片大片大片 | 精品乱子伦 | 精品国产精品三级精品av网址 | 精品乱子伦一区二区三区 | 日本黄网在线观看 | 黄色动漫软件 | 欧美九九视频 | 国产十八熟妇av成人一区 | 好吊妞这里有精品 | 国产区91 | 成人自拍av | 中文字幕自拍 | 一级二级在线观看 | 国产视频123 | 18成人在线| 黄色大片日本 | 久久色资源网 | 亚洲在线中文字幕 | 婷婷丁香综合 | 日本中文字幕成人 | 免费在线亚洲 | 国产人人插| 激情超碰在线 | 九九99精品| 日日摸天天添天天添破 | 91网入口| 亚洲精品123区 | 午夜色综合| 日韩欧美成人一区二区 | 午夜国产一级 | 欧美一级高潮片 | 2023毛片 | 久久逼逼 | 国产性hd| 高清一区二区在线 | 天天综合天天色 | 黄色天堂网 | 国产精品亚洲一区二区三区在线观看 |