Thanks.
It seems that the answers differ in the following test case
25 5
1 0 4 -10 14 -28 33 -53 60 -86 94 -128 137 -177 187 -234 247 -298 314 -371 389 -452 473 -541 564
Thanks.
It seems that the answers differ in the following test case
25 5
1 0 4 -10 14 -28 33 -53 60 -86 94 -128 137 -177 187 -234 247 -298 314 -371 389 -452 473 -541 564
Can someone give hints for IOI Training Camp 20XX. I even looked up the code on github, but can't understand what it does.
//It should belong m1 = a[0]+a[1];long current = a[0]+a[1];for(int i=1;i<n-1;i++){current = Math.max(current+b[i]-a[i]+a[i+1], a[i-1]+b[i]+a[i+1]);m1=Math.max(current, a[i]+a[i+1]));}
instead of
long m1 = a[0]+a[1];long current = a[0]+a[1];for(int i=1;i<n-1;i++){current =Math.max(current+b[i]-a[i]+a[i-1], a[i-1]+b[i]+a[i+1]);m1=Math.max(current, a[i]+a[i+1]));}
Can anyone help me to find what's wrong with my solution. Even small testcases where my code fails would be helpful. EDIT:Got it.
#include <bits/stdc++.h>#define ll long long#define fr(i,n) for(int i=0;i<n;i++)#define pb push_back#define inf (1<<31)#define xx first#define yy second#define all(c) c.begin(),c.end()using namespace std;int main() {ios::sync_with_stdio(0);int n;ifstream File;File.open("test.in");File>>n;vector<long long int> a(n),b(n);vector<long long int> f(n);
For anyone interested, I found a nice explanation of the crux of the problem.
Sorting a sequence by swapping adjacent elements using minimum swaps
You can test your code here.
Also solutions of problems can be found here, and you can generate random test inputs (even if your logic is different).
ioi-training/INOI Solutions at master · keshav57/ioi-training · GitHub