Submission #567331

# Submission time Handle Problem Language Result Execution time Memory
567331 2022-05-23T10:36:04 Z Dodo Kitchen (BOI19_kitchen) C++14
0 / 100
1 ms 212 KB
#include <bits/stdc++.h>
#define ll long long
#define endl '\n'
#define pb push_back

using namespace std;
const ll mx=1007, INF=1e18L+5;

int main()
{
  ios::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);

  ll n,m,k;
  cin>>n>>m>>k;
  vector<ll>v(m);
  ll sum=0;
  for(int i=0;i<n;i++)
  {
    ll x;
    cin>>x;
    sum+=x;
  }

  for(int i=0;i<m;i++)cin>>v[i];
  sort(v.begin(),v.end());

  ll u=lower_bound(v.begin(),v.end(),sum)-v.begin();
  ll ans=-1;

  if(u!=v.size())
    ans=v[u]-sum;

  for(int i=1;i<m;i++)
  {
    v[i]+=v[i-1];
  }

  u=lower_bound(v.begin(),v.end(),sum)-v.begin();
  if(u==v.size()&&ans==-1)cout<<"Impossible";
  else
  {
    ll x=v[u];
    int i=0;
    for(;i<u;i++)
      if(x-v[i]>=sum)x-=v[i];
    ll j=u;
    for(;j<m;j++,i++)
    {
      if(v[j]-v[i]>=sum)
      {
        x=min(x,(v[j]-v[i])-sum);
      }
    }
    x=x-sum;
    if(ans==-1)ans=x;
    else ans=min(ans,x);
    cout <<ans<<endl;
  }
  return 0;
}
/*
3 3 1
3 3 2
3 3 3
*/

Compilation message

kitchen.cpp: In function 'int main()':
kitchen.cpp:32:7: warning: comparison of integer expressions of different signedness: 'long long int' and 'std::vector<long long int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   32 |   if(u!=v.size())
      |      ~^~~~~~~~~~
kitchen.cpp:41:7: warning: comparison of integer expressions of different signedness: 'long long int' and 'std::vector<long long int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   41 |   if(u==v.size()&&ans==-1)cout<<"Impossible";
      |      ~^~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 0 ms 212 KB Output is correct
3 Correct 0 ms 212 KB Output is correct
4 Incorrect 0 ms 212 KB Output isn't correct
5 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 0 ms 212 KB Output is correct
3 Correct 0 ms 212 KB Output is correct
4 Incorrect 0 ms 212 KB Output isn't correct
5 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 0 ms 212 KB Output is correct
2 Incorrect 1 ms 212 KB Output isn't correct
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 0 ms 212 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 0 ms 212 KB Output is correct
3 Correct 0 ms 212 KB Output is correct
4 Incorrect 0 ms 212 KB Output isn't correct
5 Halted 0 ms 0 KB -