This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#include<bits/stdc++.h>
#define int long long
using namespace std;
char c, d;
int a, b, n, i, j, k;
long long ans, res, ans2=1e18;
struct st
{
int a, b;
};
vector<st>v;
bool cmp(st a, st b)
{
return a.a+a.b<b.a+b.b;
}
main()
{
ios_base::sync_with_stdio(!cin.tie(NULL));
for(cin>>k>>n;i++<n;)
{
cin>>c>>a>>d>>b;
if(c==d)ans+=abs(b-a);
else ans++,v.push_back({a, b});
}
sort(v.begin(), v.end(), cmp);
for(i=0;i<=v.size();i++)
{
vector<int>V;res=0;
for(j=0;j<i;j++)
{
V.push_back(v[j].a);V.push_back(v[j].b);
}
sort(V.begin(), V.end());
for(k=0;k<V.size()/2;k++)res-=V[k];
for(k=V.size()/2;k<V.size();k++)res+=V[k];
V.clear();
for(j=i;j<v.size();j++)
{
V.push_back(v[j].a);V.push_back(v[j].b);
}
sort(V.begin(), V.end());
for(k=0;k<V.size()/2;k++)res-=V[k];
for(k=V.size()/2;k<V.size();k++)res+=V[k];
ans2=min(ans2, res);
}
cout<<ans+ans2;
}
Compilation message (stderr)
bridge.cpp:16:6: warning: ISO C++ forbids declaration of 'main' with no type [-Wreturn-type]
16 | main()
| ^
bridge.cpp: In function 'int main()':
bridge.cpp:26:14: warning: comparison of integer expressions of different signedness: 'long long int' and 'std::vector<st>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
26 | for(i=0;i<=v.size();i++)
| ~^~~~~~~~~~
bridge.cpp:34:18: 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]
34 | for(k=0;k<V.size()/2;k++)res-=V[k];
| ~^~~~~~~~~~~
bridge.cpp:35:27: 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]
35 | for(k=V.size()/2;k<V.size();k++)res+=V[k];
| ~^~~~~~~~~
bridge.cpp:37:18: warning: comparison of integer expressions of different signedness: 'long long int' and 'std::vector<st>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
37 | for(j=i;j<v.size();j++)
| ~^~~~~~~~~
bridge.cpp:42:18: 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]
42 | for(k=0;k<V.size()/2;k++)res-=V[k];
| ~^~~~~~~~~~~
bridge.cpp:43:27: 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]
43 | for(k=V.size()/2;k<V.size();k++)res+=V[k];
| ~^~~~~~~~~
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |