Submission #450316

# Submission time Handle Problem Language Result Execution time Memory
450316 2021-08-02T13:47:14 Z cmorax Potatoes and fertilizers (LMIO19_bulves) C++17
Compilation error
0 ms 0 KB
#include <bits/stdc++.h>
using namespace std;

#define int long long;

int N;
long long fst = 0; // value of DP function at 0
priority_queue<int> points; // points where DP function changes slope

signed main() {
    cin >> N;
    vector<ll> dif(N+1);
    for (int i = 1; i <= N; ++i) {
        int a,b; cin >> a >> b;
        dif[i] = a-b+dif[i-1];
    }
    assert(dif[N] >= 0); // assume solution exists
    for (int i = 1; i < N; ++i) {
        if (dif[i] < 0) fst -= dif[i], dif[i] = 0;
        points.push(dif[i]); points.push(dif[i]);

        fst += points.top() - dif[i];

        points.pop();
    }

    if(N == 1){
        cout << 0 << endl;
        return 0;
    }

    int mult = 0;
    int last = points.top();
    while(!points.empty()){
        int at = points.top();
        
        //cout << "/ " << at << " " << last << " " << mult << endl;

        if(at <= dif[N]){
            fst += (last - dif[N]) * mult;
            break;
        }

        fst += (last - at) * mult;

        last = at;
        mult ++;
        points.pop();
    }

    cout << fst << endl;
}

Compilation message

bulves.cpp:4:18: error: declaration does not declare anything [-fpermissive]
    4 | #define int long long;
      |                  ^~~~
bulves.cpp:6:1: note: in expansion of macro 'int'
    6 | int N;
      | ^~~
bulves.cpp:6:5: error: 'N' does not name a type
    6 | int N;
      |     ^
bulves.cpp:4:18: error: template argument 1 is invalid
    4 | #define int long long;
      |                  ^~~~
bulves.cpp:8:16: note: in expansion of macro 'int'
    8 | priority_queue<int> points; // points where DP function changes slope
      |                ^~~
bulves.cpp:4:18: error: template argument 2 is invalid
    4 | #define int long long;
      |                  ^~~~
bulves.cpp:8:16: note: in expansion of macro 'int'
    8 | priority_queue<int> points; // points where DP function changes slope
      |                ^~~
bulves.cpp:4:18: error: template argument 3 is invalid
    4 | #define int long long;
      |                  ^~~~
bulves.cpp:8:16: note: in expansion of macro 'int'
    8 | priority_queue<int> points; // points where DP function changes slope
      |                ^~~
bulves.cpp:8:19: error: expected unqualified-id before '>' token
    8 | priority_queue<int> points; // points where DP function changes slope
      |                   ^
bulves.cpp: In function 'int main()':
bulves.cpp:11:12: error: 'N' was not declared in this scope
   11 |     cin >> N;
      |            ^
bulves.cpp:12:12: error: 'll' was not declared in this scope
   12 |     vector<ll> dif(N+1);
      |            ^~
bulves.cpp:12:14: error: template argument 1 is invalid
   12 |     vector<ll> dif(N+1);
      |              ^
bulves.cpp:12:14: error: template argument 2 is invalid
bulves.cpp:4:18: error: declaration does not declare anything [-fpermissive]
    4 | #define int long long;
      |                  ^~~~
bulves.cpp:13:10: note: in expansion of macro 'int'
   13 |     for (int i = 1; i <= N; ++i) {
      |          ^~~
bulves.cpp:13:14: error: 'i' was not declared in this scope
   13 |     for (int i = 1; i <= N; ++i) {
      |              ^
bulves.cpp:13:27: error: expected ')' before ';' token
   13 |     for (int i = 1; i <= N; ++i) {
      |         ~                 ^
      |                           )
bulves.cpp:13:5: warning: this 'for' clause does not guard... [-Wmisleading-indentation]
   13 |     for (int i = 1; i <= N; ++i) {
      |     ^~~
bulves.cpp:13:29: note: ...this statement, but the latter is misleadingly indented as if it were guarded by the 'for'
   13 |     for (int i = 1; i <= N; ++i) {
      |                             ^~
bulves.cpp:13:31: error: 'i' was not declared in this scope
   13 |     for (int i = 1; i <= N; ++i) {
      |                               ^
bulves.cpp:4:18: error: declaration does not declare anything [-fpermissive]
    4 | #define int long long;
      |                  ^~~~
bulves.cpp:18:10: note: in expansion of macro 'int'
   18 |     for (int i = 1; i < N; ++i) {
      |          ^~~
bulves.cpp:18:26: error: expected ')' before ';' token
   18 |     for (int i = 1; i < N; ++i) {
      |         ~                ^
      |                          )
bulves.cpp:18:5: warning: this 'for' clause does not guard... [-Wmisleading-indentation]
   18 |     for (int i = 1; i < N; ++i) {
      |     ^~~
bulves.cpp:18:28: note: ...this statement, but the latter is misleadingly indented as if it were guarded by the 'for'
   18 |     for (int i = 1; i < N; ++i) {
      |                            ^~
bulves.cpp:4:18: error: declaration does not declare anything [-fpermissive]
    4 | #define int long long;
      |                  ^~~~
bulves.cpp:32:5: note: in expansion of macro 'int'
   32 |     int mult = 0;
      |     ^~~
bulves.cpp:32:9: error: 'mult' was not declared in this scope
   32 |     int mult = 0;
      |         ^~~~
bulves.cpp:4:18: error: declaration does not declare anything [-fpermissive]
    4 | #define int long long;
      |                  ^~~~
bulves.cpp:33:5: note: in expansion of macro 'int'
   33 |     int last = points.top();
      |     ^~~
bulves.cpp:33:9: error: 'last' was not declared in this scope
   33 |     int last = points.top();
      |         ^~~~
bulves.cpp:33:16: error: 'points' was not declared in this scope; did you mean 'printf'?
   33 |     int last = points.top();
      |                ^~~~~~
      |                printf
bulves.cpp:4:18: error: declaration does not declare anything [-fpermissive]
    4 | #define int long long;
      |                  ^~~~
bulves.cpp:35:9: note: in expansion of macro 'int'
   35 |         int at = points.top();
      |         ^~~
bulves.cpp:35:13: error: 'at' was not declared in this scope
   35 |         int at = points.top();
      |             ^~