題目
題意
一個(gè)長(zhǎng)度為n的圈蝗岖,有m個(gè)任務(wù)碉输,每個(gè)任務(wù)要在對(duì)應(yīng)的點(diǎn)(mi==圈的當(dāng)前位置)完成跟继,問(wèn)最少要多少時(shí)間。
代碼
#include<bits/stdc++.h>
int main()
{
int n,m,t;
scanf("%d%d",&n,&m);
__int64 ans=0,pos=1;
for(int i=0; i<m; i++) {
scanf("%d",&t);
if(pos==t) continue;
if(t>pos){
ans+=t-pos;
}else{
ans+=t+n-pos;
}
pos=t;
}
printf("%I64d\n",ans);
return 0;
}