Submission #896373

# Submission time Handle Problem Language Result Execution time Memory
896373 2024-01-01T10:37:40 Z DQC Potatoes and fertilizers (LMIO19_bulves) C++14
0 / 100
1 ms 2396 KB
#include<bits/stdc++.h>
#define fi first
#define se second
#define int long long
using namespace std;
using ll=long long;
int n;
int a[500005],b[500005];
int32_t main()
{
    cin.tie(0)->sync_with_stdio(0);
    //freopen(".inp","r",stdin);
    //freopen(".out","w",stdout);
    cin>>n;
    for(int i=1;i<=n;i++) cin>>a[i]>>b[i];
    int ans=0;
    for(int i=1;i<=n;i++) if(a[i]<b[i])
    {
      for(int l=i-1,r=i+1;a[i]<b[i]&&(l>0||r<=n);l--,r++)
      {
        if(l>0)
        {
          int cnt=min(a[l]-b[l],b[i]-a[i]);
          ans+=cnt*(i-l);
          a[l]-=cnt;
          a[i]+=cnt;
        }
        if(a[i]>=b[i]) break;
        if(r<=n)
        {
          int cnt=min(a[r],b[i]-a[i]);
          ans+=cnt*(r-i);
          a[r]-=cnt;
          a[i]+=cnt;
        }
      }
    }
    cout<<ans;
    return 0;
}
# Verdict Execution time Memory Grader output
1 Correct 0 ms 2396 KB Output is correct
2 Correct 1 ms 2396 KB Output is correct
3 Incorrect 1 ms 2396 KB Output isn't correct
4 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 0 ms 2396 KB Output is correct
2 Correct 1 ms 2396 KB Output is correct
3 Incorrect 1 ms 2396 KB Output isn't correct
4 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 0 ms 2396 KB Output is correct
2 Correct 1 ms 2396 KB Output is correct
3 Correct 1 ms 2392 KB Output is correct
4 Incorrect 1 ms 2396 KB Output isn't correct
5 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 0 ms 2396 KB Output is correct
2 Correct 1 ms 2396 KB Output is correct
3 Incorrect 1 ms 2396 KB Output isn't correct
4 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 0 ms 2396 KB Output is correct
2 Correct 1 ms 2396 KB Output is correct
3 Incorrect 1 ms 2396 KB Output isn't correct
4 Halted 0 ms 0 KB -