Submission #581047

#TimeUsernameProblemLanguageResultExecution timeMemory
581047AGEHolding (COCI20_holding)C++14
22 / 110
2096 ms316 KiB
#include<bits/stdc++.h> #define F first #define S second #define int long long #define pb push_back using namespace std; const int N=1e6,M=2e3,mod=1e9+7; vector<pair<int,int>>v; int Final_ans=1e18; int n,l,r,k,a[N]; void bt(int index){ if(index==n+1){ int ans=0,ans2=0; if(v.size()!=r-l+1) return ; sort(v.begin(),v.end()); for(int i=0;i<v.size();i++) ans+=abs(v[i].F-(l+i)),ans2+=v[i].S; if(ans>k) return ; Final_ans=min(Final_ans,ans2); return ; } v.pb({index,a[index]}); bt(index+1); v.pop_back(); bt(index+1); } main() { cin>>n>>l>>r>>k; for(int i=1;i<=n;i++) cin>>a[i]; bt(1); cout<<Final_ans<<endl; return 0; }

Compilation message (stderr)

holding.cpp: In function 'void bt(long long int)':
holding.cpp:18:20: warning: comparison of integer expressions of different signedness: 'std::vector<std::pair<long long int, long long int> >::size_type' {aka 'long unsigned int'} and 'long long int' [-Wsign-compare]
   18 |         if(v.size()!=r-l+1)
      |            ~~~~~~~~^~~~~~~
holding.cpp:23:22: warning: comparison of integer expressions of different signedness: 'long long int' and 'std::vector<std::pair<long long int, long long int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   23 |         for(int i=0;i<v.size();i++)
      |                     ~^~~~~~~~~
holding.cpp: At global scope:
holding.cpp:41:1: warning: ISO C++ forbids declaration of 'main' with no type [-Wreturn-type]
   41 | main()
      | ^~~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...