339B codeforces
Xenia and ringroad
#include <iostream> #include <deque> using namespace std; long long int n,m,my=1,s=0; deque<long long int>dk; int main() { cin>>n>>m; for(int i=0;i<m;i++){int t;cin>>t;dk.push_front(t);} while(dk.back()==1)dk.pop_back(); while(!dk.empty()){ s+=(my==dk.back())?n:(my<dk.back())?dk.back()-my:n-(my-dk.back()); my=dk.back(); do{ dk.pop_back(); } while(my==dk.back()); } cout<<s<<"\n"; return 0; }
0 التعليقات:
إرسال تعليق