SHARE
TWEET

codeforce - xenia and ringroad

jakaria_hossain Apr 10th, 2019 69 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. #include<bits/stdc++.h>
  2. using namespace std;
  3. #define fastread()(ios_base::sync_with_stdio(false),cin.tie(NULL));
  4. #define ll long long
  5. int main()
  6. {
  7.     int a,b;
  8.     fastread()
  9.     cin>>a>>b;
  10.     int ara[b+1];
  11.     ll ans=0;
  12.     for(int i=0; i<b; i++)
  13.     {
  14.         cin>>ara[i];
  15.         if(i==0)
  16.         {
  17.             if(ara[i]>=1)
  18.             {
  19.                 ans+=ara[i]-1;
  20.             }
  21.             else
  22.             {
  23.                 ans+=a+ara[i]-1;
  24.             }
  25.         }
  26.         else
  27.         {
  28.             if(ara[i]>=ara[i-1])
  29.             {
  30.                 ans+=ara[i]-ara[i-1];
  31.             }
  32.             else
  33.             {
  34.                 ans+=a+ara[i]-ara[i-1];
  35.             }
  36.         }
  37.     }
  38.     cout<<ans<<endl;
  39.     return 0;
  40. }
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top