Submission #882354

# Submission time Handle Problem Language Result Execution time Memory
882354 2023-12-03T05:05:02 Z Requiem Potatoes and fertilizers (LMIO19_bulves) C++17
0 / 100
1 ms 4444 KB
#include<bits/stdc++.h>
#define int long long
#define pb push_back
#define fast ios_base::sync_with_stdio(false), cin.tie(nullptr), cout.tie(nullptr);
#define MOD 1000000007
#define INF 1e18
#define fi first
#define se second
#define endl "\n"
#define FOR(i,a,b) for(int i=a;i<=b;i++)
#define FORD(i,a,b) for(int i=a;i>=b;i--)
#define sz(a) ((int)(a).size())
#define pi 3.14159265359
#define TASKNAME "bulves"
template<typename T> bool maximize(T &res, const T &val) { if (res < val){ res = val; return true; }; return false; } 
template<typename T> bool minimize(T &res, const T &val) { if (res > val){ res = val; return true; }; return false; } 
using namespace std; 
typedef pair<int,int> ii; 
typedef pair<int,ii> iii; 
typedef vector<int> vi; 
const int MAXN = 5e5 + 9;
int n;
int a[MAXN],b[MAXN],A,B;
namespace sub1 {
    void solve(){
       int ans = 0, bring = 0;
       for(int i=1;i<=n;i++){
           ans += abs(bring);
           if (a[i] == b[i]) continue;
           if (a[i] < b[i]) bring -= b[i] - a[i];
           else bring += a[i] - b[i];
       }
    }
}
namespace sub5{
    int dif[MAXN];
    void solve(){
        priority_queue<int> pq;
        int ans = 0;
        int d = 0;
        for(int i=1;i<=n;i++){
            dif[i] = dif[i-1] + a[i] - b[i];
        }
        pq.push(dif[1]);
        for(int i=2;i<n;i++){
            if (dif[i] < 0) ans -= dif[i], dif[i] = 0;
            if (dif[i] > pq.top()){
                pq.push(dif[i]);
            }
            else{
                ans += pq.top() - dif[i];
                pq.push(dif[i]);
                pq.push(dif[i]);
                pq.pop();
            }
        }
        cout<<ans<<endl;
    }
}
main() 
{ 
    fast; 
   if (fopen(TASKNAME".inp","r")){
        freopen(TASKNAME".inp","r",stdin); 
        freopen(TASKNAME".out","w",stdout); 
   }
   cin>>n;
   for(int i=1;i<=n;i++){
       cin>>a[i]>>b[i];
       A += a[i];
       B += b[i];
   } 
   assert(A >= B);
   sub5::solve();
} 

Compilation message

bulves.cpp: In function 'void sub5::solve()':
bulves.cpp:40:13: warning: unused variable 'd' [-Wunused-variable]
   40 |         int d = 0;
      |             ^
bulves.cpp: At global scope:
bulves.cpp:60:1: warning: ISO C++ forbids declaration of 'main' with no type [-Wreturn-type]
   60 | main()
      | ^~~~
bulves.cpp: In function 'int main()':
bulves.cpp:64:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   64 |         freopen(TASKNAME".inp","r",stdin);
      |         ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~
bulves.cpp:65:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   65 |         freopen(TASKNAME".out","w",stdout);
      |         ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Incorrect 1 ms 4444 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 1 ms 4444 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 1 ms 4444 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 1 ms 4444 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 1 ms 4444 KB Output isn't correct
2 Halted 0 ms 0 KB -