lol :: IO int
lol = go -1 0 0 0
where go k m n p = case k of
-1 -> do{
q <- readLn ;
go 0 0 0 q
}
p -> do{
putStrLn $ show $ n
}
_ -> do{
q <- readLn ;
go (k+1) q (if q > m then n+q-m else n) p
return()
}
I(a haskell beginner) am doing some practise questions. I have written a recursive function but i don't know how to use it in main. Please help me to do solve this problem. This is my idea in C++ and I got it accepted.
#include<iostream>
using namespace std;
int main(){
long long int prev=0;
long long int count,ans=0;
cin >> count;
long long int p;
for(int i=0; i<count ;i++){
cin >> p;
if(p>prev){
ans+=p-prev;
}
prev=p;
}
cout << ans << endl;
}