Language: C++

#include <functional>
#include <iostream>
int p[100100],c[100100],e[100100];
int dp[2][100100];//dp[i+1][j]:=i番目までの箱を使ってj個の饅頭
int main()
{
    int n,m;
    cin >> n >> m;
    int sum=0;
    for(int i=0;i<n;i++)cin >> p[i];
    for(int i=0;i<m;i++)cin >> c[i] >> e[i];
    sort(p,p+n,greater<int>());
    for(int i=0;i<n;i++)p[i+1]+=p[i];
    for(int i=0;i<2;i++)
    {
        for(int j=0;j<=n;j++)
        {
            dp[i][j]=INF;
        }
    }
    dp[0][0]=0;
    for(int i=0;i<m;i++)
    {
        for(int j=0;j<=n;j++)
        {
            dp[(i+1)%2][j]=min(dp[i%2][j],dp[i%2][max(j-c[i],0)]+e[i]);
        }
    }
    int ans=0;
    for(int i=1;i<=n;i++)
    {
        ans=max(ans,p[i-1]-dp[m%2][i]);
    }
    cout << ans << endl;
    return 0;
}

Compiler output:
a.cc: In function 'int main()':
a.cc:8:5: error: 'cin' was not declared in this scope; did you mean 'std::cin'?
    8 |     cin >> n >> m;
      |     ^~~
      |     std::cin
In file included from a.cc:2:
/usr/include/c++/14/iostream:62:18: note: 'std::cin' declared here
   62 |   extern istream cin;           ///< Linked to standard input
      |                  ^~~
a.cc:12:16: error: 'greater' was not declared in this scope; did you mean 'std::greater'?
   12 |     sort(p,p+n,greater<int>());
      |                ^~~~~~~
      |                std::greater
In file included from /usr/include/c++/14/functional:49,
                 from a.cc:1:
/usr/include/c++/14/bits/stl_function.h:353:12: note: 'std::greater' declared here
  353 |     struct greater;
      |            ^~~~~~~
a.cc:12:24: error: expected primary-expression before 'int'
   12 |     sort(p,p+n,greater<int>());
      |                        ^~~
a.cc:12:5: error: 'sort' was not declared in this scope; did you mean 'short'?
   12 |     sort(p,p+n,greater<int>());
      |     ^~~~
      |     short
a.cc:18:22: error: 'INF' was not declared in this scope
   18 |             dp[i][j]=INF;
      |                      ^~~
a.cc:26:51: error: 'max' was not declared in this scope; did you mean 'std::max'?
   26 |             dp[(i+1)%2][j]=min(dp[i%2][j],dp[i%2][max(j-c[i],0)]+e[i]);
      |                                                   ^~~
      |                                                   std::max
In file included from /usr/include/c++/14/bits/hashtable_policy.h:36,
                 from /usr/include/c++/14/bits/hashtable.h:35,
                 from /usr/include/c++/14/bits/unordered_map.h:33,
                 from /usr/include/c++/14/unordered_map:41,
                 from /usr/include/c++/14/functional:63:
/usr/include/c++/14/bits/stl_algobase.h:303:5: note: 'std::max' declared here
  303 |     max(const _Tp& __a, const _Tp& __b, _Compare __comp)
      |     ^~~
a.cc:26:28: error: 'min' was not declared in this scope; did you mean 'std::min'?
   26 |             dp[(i+1)%2][j]=min(dp[i%2][j],dp[i%2][max(j-c[i],0)]+e[i]);
      |                            ^~~
      |                            std::min
/usr/include/c++/14/bits/stl_algobase.h:281:5: note: 'std::min' declared here
  281 |     min(const _Tp& __a, const _Tp& __b, _Compare __comp)
      |     ^~~
a.cc:32:13: error: 'max' was not declared in this scope; did you mean 'std::max'?
   32 |         ans=max(ans,p[i-1]-dp[m%2][i]);
      |             ^~~
      |             std::max
/usr/include/c++/14/bits/stl_algobase.h:303:5: note: 'std::max' declared here
  303 |     max(const _Tp& __a, const _Tp& __b, _Compare __comp)
      |     ^~~
a.cc:34:5: error: 'cout' was not declared in this scope; did you mean 'std::cout'?
   34 |     cout << ans << endl;
      |     ^~~~
      |     std::cout
/usr/include/c++/14/iostream:63:18: note: 'std::cout' declared here
   63 |   extern ostream cout;          ///< Linked to standard output
      |                  ^~~~
a.cc:34:20: error: 'endl' was not declared in this scope; did you mean 'std::endl'?
   34 |     cout << ans << endl;
      |                    ^~~~
      |                    std::endl
In file included from /usr/include/c++/14/iostream:41:
/usr/include/c++/14/ostream:744:5: note: 'std::endl' declared here
  744 |     endl(basic_ostream<_CharT, _Traits>& __os)
      |     ^~~~