Submission #295720

#TimeUsernameProblemLanguageResultExecution timeMemory
295720RezwanArefin01Potatoes and fertilizers (LMIO19_bulves)C++17
100 / 100
232 ms15208 KiB
#include <bits/stdc++.h>
using namespace std; 

typedef long long ll;
typedef pair<int, int> ii; 

const int N = 5e5 + 5; 

int n; 
ll p[N]; 

int main() {
  int n; 
  scanf("%d", &n); 

  for(int i = 1; i <= n; ++i) {
    int a, b; 
    scanf("%d %d", &a, &b); 
    p[i] = p[i - 1] + a - b; 
  }

  ll ans = 0; 
  priority_queue<ll> Q; 
  for(int i = 1; i <= n; ++i) {
    if(p[i] < 0) ans -= p[i], p[i] = 0; 
    if(p[i] > p[n]) ans += p[i] - p[n], p[i] = p[n]; 
    Q.push(p[i]); 
    Q.push(p[i]); 
    ans += Q.top() - p[i]; 
    Q.pop(); 
  }
  
  printf("%lld\n", ans); 
    
  return 0;
}

Compilation message (stderr)

bulves.cpp: In function 'int main()':
bulves.cpp:14:8: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
   14 |   scanf("%d", &n);
      |   ~~~~~^~~~~~~~~~
bulves.cpp:18:10: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
   18 |     scanf("%d %d", &a, &b);
      |     ~~~~~^~~~~~~~~~~~~~~~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...