Problem:
Maximum Profit
You can obtain profits from foreign exchange margin transactions. For example,  if you buy 1000 dollar at a rate of 100 yen per dollar, and sell them at a rate of 108 yen per dollar, you can obtain (108 - 100) × 1000 = 8000 yen.
Write a program which reads values of a currency $R_t$ at a certain time $t$ ($t = 0, 1, 2, ... n-1$), and reports the maximum value of $R_j - R_i$ where $j > i$ .
Input
The first line contains an integer $n$. In the following $n$ lines, $R_t$ ($t = 0, 1, 2, ... n-1$) are given in order.
Output
Print the maximum value in a line.
Constraints
$2 \leq n \leq 200,000$
$1 \leq R_t \leq 10^9$
Sample Input 1
6
5
3
1
3
4
3
Sample Output 1
3
Sample Input 2
3
4
3
2
Sample Output 2
-1

Submitted solutions:

code_snippet: #include<iostream>
using namespace std;
int main ( ) {
	int n = 0, min = 0, result = -1000000000, temp = 0;
	cin >> n;
	cin >> min;
	for (int i = 0; i < n-1; i++) {
		cin >> temp;
		if (temp - min > result) {
			result = temp - min;
		}
		if (temp < min) {
			min = temp;
		}
		
	}
	cout << result << endl;
	
	
	return 0;
}
accuracy: 1
time_ms: 40
memory_kb: 3440
final_rank: 6

code_snippet: #include<bits/stdc++.h> 
using namespace std;
int gcd(int a, int b) {
    while (b != 0) {
        int temp = b;
        b = a % b;
        a = temp;
    }
    return a;
}
int lcm(int a, int b) {
    return a / gcd(a, b) * b;
}
int main(){
      ios::sync_with_stdio(false);
        cin.tie(nullptr);
        int n ; 
        cin>>n;
        int a[n] , result = INT_MIN;
        for(int i = 0 ; i<n ; i++){
            cin>>a[i];
        }
            int b[n];
            b[0] = a[0] ;
            for(int i = 1 ; i < n ; i++){
                b[i] = min(b[i-1] , a[i]);
            }
            for(int i = 1 ; i < n ; i++){
                result = max(result , a[i] - b[i-1]);
            }
        cout<<result<<"\n";
        }
accuracy: 1
time_ms: 10
memory_kb: 5016
final_rank: 3

code_snippet: #include <bits/stdc++.h>
using namespace std;

typedef long long ll;

int main() {
    ll n;
    cin>>n;
    ll num;
    cin>>num;
    ll ans = -100000000000000;
    ll now = num;
    for (int i = 1; i < n; i++) {
        cin>>num;
        ans = max(ans, num-now);
        now = min(now, num);
    }
    cout<<ans<<"\n";
    return 0;
}
accuracy: 1
time_ms: 30
memory_kb: 3584
final_rank: 2

code_snippet: #include<iostream>
using namespace std;

int main(){
    int n;
    cin>>n;
    int minprice=2000000001,maxpr=-1000000001;
    for(int i=0;i<n;i++){
        int a;
        cin>>a;
        maxpr=max(maxpr,a-minprice);
        minprice=min(a,minprice);
    }
    cout<<maxpr<<endl;
}
accuracy: 1
time_ms: 40
memory_kb: 3436
final_rank: 4

code_snippet: #include <iostream>
#include <cmath>
#include <iomanip>
using namespace std;

int main() {
	int n ;
	cin >> n;
	long ans= -9999999999,min;
	cin>>min;
	for (int i = 0; i < n-1; i++) {
			long a;
			cin>>a;
			if(ans<(a-min)){ans=a-min;}
			if(a<=min){min=a;}
		}
		cout<<ans<<endl;
		return 0;
}
accuracy: 1
time_ms: 40
memory_kb: 3436
final_rank: 4

code_snippet: #include <iostream>
#include <cmath>
#include <iomanip>
using namespace std;

int main() {
	int n;
	cin >> n;
	long t = -999999999999999, a[10000];
		for (int i = 0; i < n; i++) {
		    cin>>a[i];
		}
	for (int i = 0; i < n; i++) {
	        int j = i+1;
		    while(j<=n-1)
		    {
		        if(a[j]- a[i]>t){t=a[j]- a[i];}
		        j++;
		    }
		}
		cout<<fixed<<setprecision(21);
		cout<<t<<endl;
		return 0;
}
accuracy: 0.875
time_ms: 20
memory_kb: 3440
final_rank: 20

code_snippet: #include<bits/stdc++.h>
using namespace std;
int main(){
    int n;cin >> n;
    vector<int>v(n);
    for(int i=0;i<n;i++){
        cin >> v.at(i);
    }
    int minv = v.at(0);
    int maxv = v[1]-v[0];
    for(int i=1;i<n;i++){
        maxv=max(maxv,v.at(i)-minv);
        minv=min(minv,v.at(i));
    }
    cout << maxv << endl;
}
accuracy: 1
time_ms: 40
memory_kb: 3864
final_rank: 9

code_snippet: #include<bits/stdc++.h>
using namespace std;
int n;
int a[200005];
int mx=-2000005,mn=0x3f3f3f3f;
int main(){
	cin>>n;
	for(int i=1;i<=n;i++)cin>>a[i];
	mx=-2000000005;
	mn=a[1];
	for(int i=2;i<=n;i++){
		mx=max(mx,a[i]-mn);
		mn=min(mn,a[i]);
	}
	cout<<mx<<endl;
	return 0;
}
accuracy: 1
time_ms: 40
memory_kb: 4116
final_rank: 12

code_snippet: #include <iostream>
using namespace std;

int main(){
    int n, R[200000];
    cin >> n >> R[0];

    int minv = R[0], maxv = -1e9;

    for(int i = 1; i < n; i++){
        cin >> R[i];
        maxv = maxv > (R[i] - minv) ? maxv : R[i] - minv;
        minv = R[i] < minv ? R[i] : minv;        
    }
    cout << maxv << endl;
    
    return 0;
}
accuracy: 1
time_ms: 40
memory_kb: 4144
final_rank: 14

code_snippet: #include <iostream>
using namespace std;

int main(){
    int n;
    cin >> n;
    int R[200000];
    for(int i = 0; i < n; i++)
        cin >> R[i];

    int minv = R[0], maxv = -1e9;

    for(int j = 1; j < n; j++){
        maxv = maxv > (R[j] - minv) ? maxv : R[j] - minv;
        minv = R[j] < minv ? R[j] : minv;        
    }
    cout << maxv << endl;
    
    return 0;
}
accuracy: 1
time_ms: 40
memory_kb: 4216
final_rank: 17

code_snippet: #include <bits/stdc++.h>
using namespace std;

int main() {
    int n;
    cin >> n;
    vector<int> v(n);
    for (int i = 0; i < n; i++) cin >> v[i];

    int minv = v[0];
    int maxv = v[1] - v[0]; // 最初の2つの差を初期値に
    for (int i = 1; i < n; i++) {
        maxv = max(maxv, v[i] - minv);
        minv = min(minv, v[i]);
    }
    cout << maxv << endl;
}
accuracy: 1
time_ms: 40
memory_kb: 3760
final_rank: 8

code_snippet: #include <iostream>
using namespace std;

int main()
{
    int n;
    cin >> n;
    int ans = INT32_MIN, bruh;
    cin >> bruh;
    for (int i=0, tmp; i<(n-1); i++)
    {
        cin >> tmp;
        ans = max(ans, tmp-bruh);
        bruh = (bruh > tmp)? tmp : bruh;
    }
    cout << ans << "\n";
}
accuracy: 1
time_ms: 40
memory_kb: 3480
final_rank: 7

code_snippet: /*10.28*/
#include <iostream>

using namespace std;

int main() {

    int maxv, minv;

    int n;
    
    cin >> n;

    int rt[n];

    for (int i = 0;i < n;i++) cin >> rt[i];


    maxv = rt[1] - rt[0];
    minv = rt[0];
    for (int j = 1; j < n;j++) {
        maxv = max(maxv, rt[j] - minv);
        minv = min(minv, rt[j]);
    }

    cout << maxv << endl;


}
accuracy: 1
time_ms: 40
memory_kb: 4212
final_rank: 15

code_snippet: #include<iostream>
using namespace std;

int main(){
    int n, max, min, i;
    int ex[200'000];
    cin >> n;
    for(i = 0; i < n; i++) cin >> ex[i];

    min = ex[0];
    max = ex[1]-min;
    for(i = 1; i < n; i ++){
        if(ex[i]-min > max) max = ex[i]-min;
        if(ex[i] < min) min = ex[i];
    }

    cout << max << endl;
    return 0;
}
accuracy: 1
time_ms: 40
memory_kb: 4216
final_rank: 17

code_snippet: #include<iostream>
using namespace std;
int main(void){
    int n,minnn=1000000001,maxxx=-1000000001;
    cin>>n;
    int a[200000]={0};
    for(int i=0;i<n;i++){
        cin>>a[i];
    }
    minnn=min(minnn,a[0]);
    for(int i=1;i<n;i++){
        maxxx=max(maxxx,a[i]-minnn);
        minnn=min(minnn,a[i]);
    }
    cout<<maxxx<<endl;
}
accuracy: 1
time_ms: 40
memory_kb: 4216
final_rank: 17

code_snippet: #include <iostream>
#include <algorithm>
#include <vector>

using namespace std;

int main(void){
    int n;
    cin >> n;

    vector<int> a;
    for(int i = 0; i < n; i++){
        int x;
        cin >> x;
        a.push_back(x);
    }

    int maxv = -1000000000;
    int minv = a[0];


    for (int i = 1; i < n; i++)
    {
        maxv = max(maxv , a[i] - minv);
        minv = min(minv , a[i]);
    }
    
    cout << maxv << endl;

    return 0;
}
accuracy: 1
time_ms: 40
memory_kb: 4128
final_rank: 13

code_snippet: #include <bits/stdc++.h>

using namespace std;
using ll = long long;
#define rep(i, N) for (int i = 0; i < N; ++i)

int main() {
    int n;
    cin >> n;
    vector<int> R(n);
    rep(i, n) cin >> R[i];

    int currmin = R[0];
    int res = INT_MIN;
    for (int i = 1; i < n; ++i) {
        res = max(res, R[i] - currmin);
        currmin = min(currmin, R[i]);
    }

    cout << res << endl;
    return 0;
}
accuracy: 1
time_ms: 40
memory_kb: 3872
final_rank: 10

code_snippet: #include <iostream>
#include <algorithm>
using namespace std;

int main() {
    int n;
    cin >> n;
    
    int R[200000];
    for (int i = 0; i < n; i++) {
        cin >> R[i];
    }
    
    int minv = R[0];
    int maxv = R[1] - R[0];
    
    for (int j = 1; j < n; j++) {
        maxv = max(maxv, R[j] - minv);
        minv = min(minv, R[j]);
    }
    
    cout << maxv << endl;
    return 0;
}
accuracy: 1
time_ms: 40
memory_kb: 4212
final_rank: 15

code_snippet: #include <iostream>
#include <algorithm>
using namespace std;

int main(){
    int n;
    cin >> n;
    
    int R[200000];
    for (int i = 0; i < n; i++) {
        cin >> R[i];
    }
    
    int minv = R[0];
    int maxv = R[1] - R[0];
    
    for (int j = 1; j < n; j++){
        maxv = max(maxv, R[j]-minv);
        minv = min(minv, R[j]);
    }
    
    cout << maxv << endl;
    return 0;
}
accuracy: 1
time_ms: 40
memory_kb: 4100
final_rank: 11

code_snippet: #include <stdio.h>
#include <limits.h>

using namespace std;

int main(){
	int n,tmp,min=INT_MAX,max=INT_MIN;
	scanf("%d",&n);
	for(int i = 0; i < n; i++){
		scanf("%d",&tmp);
		if(max < tmp-min) max = tmp - min;
		if(min > tmp) min = tmp;
	}
	printf("%d\n",max);
	return 0;
}
accuracy: 1
time_ms: 10
memory_kb: 2976
final_rank: 1