Chef & Digits (TLE)

Please try to help me out. How can I improve my code to make it more efficient.
Question Link
My Code

#include<bits/stdc++.h>
using namespace std;
int main(){
   int n; 
   int t;
   cin>>n>>t;
   int arr[n];
   string str;
   cin>>str;
   for(int i = 0; i < str.length(); i++){
       string strPart;
       strPart.push_back(str[i]);
       arr[i] = stoi(strPart);
       strPart.pop_back();
   }
    while(t--){
        int curr;
        cin>>curr;
        int sum = 0;
        for (int j = 0; j < curr; j++)
        {
            int nowVal = arr[curr-1]-arr[j];
            if(nowVal<0){
                nowVal = -nowVal;
            }
            sum = sum + nowVal;
        }
        cout<<sum<<endl;
    }
return 0;
}

Hey @arnab2002
Thanks for sharing your doubt.
The time complexity of your code is O(n*m) that is why your code gives TLE.

Here is the link to the editorial of the problem from where you get efficient code.
https://discuss.codechef.com/t/adigit-editorial/5109

If you find any difficulty in understanding it please message me.