Submission #1154239


Source Code Expand

#include<bits/stdc++.h>
using namespace std;

typedef long long ll;

inline ll read()
{
    ll x=0,f=1;char ch=getchar();
    while(ch<'0'||ch>'9'){if(ch=='-')f=-1;ch=getchar();}
    while(ch>='0'&&ch<='9'){x=x*10+ch-'0';ch=getchar();}
    return x*f;
}

#define maxn 100100
ll a[maxn],b[maxn];
ll ans,cur;
int n;

int main()
{
	n=read();
	for(int i=1;i<=n;i++)
		a[i]=read();
	for(int i=1;i<=n;i++)
		b[i]=read();
	priority_queue<ll,vector<ll>,greater<ll> > q;
	for(int i=1;i<=n;i++)
	{
		cur+=b[i]-a[i];
		if (cur>0)
		{
			q.push(0);
			q.push(0);
		}
		else
		{
			q.push(cur);
			q.push(cur);
		}
		ans+=cur-q.top();q.pop();
	}
	while (!q.empty() && q.top()<=cur)
	{
		ans+=cur-q.top();
		q.pop();
	}
	cout<<ans<<endl;
	return 0;
}

Submission Info

Submission Time
Task H - WAAAAAAAAAAAAALL
User Ragdoll
Language C++14 (GCC 5.4.1)
Score 200
Code Size 786 Byte
Status AC
Exec Time 26 ms
Memory 2936 KB

Judge Result

Set Name Subtask1 Subtask2 All
Score / Max Score 30 / 30 30 / 30 140 / 140
Status
AC × 37
AC × 36
AC × 107
Set Name Test Cases
Subtask1 00_00_sample.txt, 00_01_sample.txt, 00_02_sample.txt, 00_03_random.txt, 00_04_random.txt, 00_05_random.txt, 00_06_random.txt, 00_07_random.txt, 00_08_random.txt, 00_09_random.txt, 00_10_random.txt, 00_11_random.txt, 00_12_random.txt, 00_13_random.txt, 00_14_random.txt, 00_15_random.txt, 00_16_random.txt, 00_17_random.txt, 00_18_random.txt, 00_19_random.txt, 00_20_random.txt, 00_21_random.txt, 00_22_random.txt, 00_23_freedom.txt, 00_24_freedom.txt, 00_25_freedom.txt, 00_26_full.txt, 00_27_full.txt, 00_28_full.txt, 00_29_min.txt, 00_30_min.txt, 00_31_min.txt, 00_32_max.txt, 00_33_max.txt, 00_34_max.txt, 00_35_max.txt, 00_36_max.txt
Subtask2 01_37_sample.txt, 01_38_sample.txt, 01_39_random.txt, 01_40_random.txt, 01_41_random.txt, 01_42_random.txt, 01_43_random.txt, 01_44_random.txt, 01_45_random.txt, 01_46_random.txt, 01_47_random.txt, 01_48_random.txt, 01_49_random.txt, 01_50_random.txt, 01_51_random.txt, 01_52_random.txt, 01_53_random.txt, 01_54_random.txt, 01_55_random.txt, 01_56_random.txt, 01_57_random.txt, 01_58_random.txt, 01_59_freedom.txt, 01_60_freedom.txt, 01_61_freedom.txt, 01_62_full.txt, 01_63_full.txt, 01_64_full.txt, 01_65_min.txt, 01_66_min.txt, 01_67_min.txt, 01_68_max.txt, 01_69_max.txt, 01_70_max.txt, 01_71_max.txt, 01_72_max.txt
All 00_00_sample.txt, 00_01_sample.txt, 00_02_sample.txt, 00_03_random.txt, 00_04_random.txt, 00_05_random.txt, 00_06_random.txt, 00_07_random.txt, 00_08_random.txt, 00_09_random.txt, 00_10_random.txt, 00_11_random.txt, 00_12_random.txt, 00_13_random.txt, 00_14_random.txt, 00_15_random.txt, 00_16_random.txt, 00_17_random.txt, 00_18_random.txt, 00_19_random.txt, 00_20_random.txt, 00_21_random.txt, 00_22_random.txt, 00_23_freedom.txt, 00_24_freedom.txt, 00_25_freedom.txt, 00_26_full.txt, 00_27_full.txt, 00_28_full.txt, 00_29_min.txt, 00_30_min.txt, 00_31_min.txt, 00_32_max.txt, 00_33_max.txt, 00_34_max.txt, 00_35_max.txt, 00_36_max.txt, 01_37_sample.txt, 01_38_sample.txt, 01_39_random.txt, 01_40_random.txt, 01_41_random.txt, 01_42_random.txt, 01_43_random.txt, 01_44_random.txt, 01_45_random.txt, 01_46_random.txt, 01_47_random.txt, 01_48_random.txt, 01_49_random.txt, 01_50_random.txt, 01_51_random.txt, 01_52_random.txt, 01_53_random.txt, 01_54_random.txt, 01_55_random.txt, 01_56_random.txt, 01_57_random.txt, 01_58_random.txt, 01_59_freedom.txt, 01_60_freedom.txt, 01_61_freedom.txt, 01_62_full.txt, 01_63_full.txt, 01_64_full.txt, 01_65_min.txt, 01_66_min.txt, 01_67_min.txt, 01_68_max.txt, 01_69_max.txt, 01_70_max.txt, 01_71_max.txt, 01_72_max.txt, 02_100_min.txt, 02_101_min.txt, 02_102_max.txt, 02_103_max.txt, 02_104_max.txt, 02_105_max.txt, 02_106_max.txt, 02_73_random.txt, 02_74_random.txt, 02_75_random.txt, 02_76_random.txt, 02_77_random.txt, 02_78_random.txt, 02_79_random.txt, 02_80_random.txt, 02_81_random.txt, 02_82_random.txt, 02_83_random.txt, 02_84_random.txt, 02_85_random.txt, 02_86_random.txt, 02_87_random.txt, 02_88_random.txt, 02_89_random.txt, 02_90_random.txt, 02_91_random.txt, 02_92_random.txt, 02_93_freedom.txt, 02_94_freedom.txt, 02_95_freedom.txt, 02_96_full.txt, 02_97_full.txt, 02_98_full.txt, 02_99_min.txt
Case Name Status Exec Time Memory
00_00_sample.txt AC 1 ms 256 KB
00_01_sample.txt AC 1 ms 256 KB
00_02_sample.txt AC 1 ms 256 KB
00_03_random.txt AC 1 ms 256 KB
00_04_random.txt AC 1 ms 256 KB
00_05_random.txt AC 1 ms 256 KB
00_06_random.txt AC 1 ms 256 KB
00_07_random.txt AC 1 ms 256 KB
00_08_random.txt AC 1 ms 256 KB
00_09_random.txt AC 1 ms 256 KB
00_10_random.txt AC 1 ms 256 KB
00_11_random.txt AC 1 ms 256 KB
00_12_random.txt AC 1 ms 256 KB
00_13_random.txt AC 1 ms 256 KB
00_14_random.txt AC 1 ms 256 KB
00_15_random.txt AC 1 ms 256 KB
00_16_random.txt AC 1 ms 256 KB
00_17_random.txt AC 1 ms 256 KB
00_18_random.txt AC 1 ms 256 KB
00_19_random.txt AC 1 ms 256 KB
00_20_random.txt AC 1 ms 256 KB
00_21_random.txt AC 2 ms 256 KB
00_22_random.txt AC 1 ms 256 KB
00_23_freedom.txt AC 1 ms 256 KB
00_24_freedom.txt AC 1 ms 256 KB
00_25_freedom.txt AC 1 ms 256 KB
00_26_full.txt AC 1 ms 256 KB
00_27_full.txt AC 1 ms 256 KB
00_28_full.txt AC 1 ms 256 KB
00_29_min.txt AC 1 ms 256 KB
00_30_min.txt AC 1 ms 256 KB
00_31_min.txt AC 1 ms 256 KB
00_32_max.txt AC 2 ms 256 KB
00_33_max.txt AC 1 ms 256 KB
00_34_max.txt AC 1 ms 256 KB
00_35_max.txt AC 1 ms 256 KB
00_36_max.txt AC 1 ms 256 KB
01_37_sample.txt AC 1 ms 256 KB
01_38_sample.txt AC 1 ms 256 KB
01_39_random.txt AC 1 ms 256 KB
01_40_random.txt AC 1 ms 256 KB
01_41_random.txt AC 1 ms 256 KB
01_42_random.txt AC 1 ms 256 KB
01_43_random.txt AC 1 ms 256 KB
01_44_random.txt AC 1 ms 256 KB
01_45_random.txt AC 1 ms 256 KB
01_46_random.txt AC 1 ms 256 KB
01_47_random.txt AC 1 ms 256 KB
01_48_random.txt AC 1 ms 256 KB
01_49_random.txt AC 1 ms 256 KB
01_50_random.txt AC 1 ms 256 KB
01_51_random.txt AC 1 ms 256 KB
01_52_random.txt AC 1 ms 256 KB
01_53_random.txt AC 1 ms 256 KB
01_54_random.txt AC 1 ms 256 KB
01_55_random.txt AC 1 ms 256 KB
01_56_random.txt AC 1 ms 256 KB
01_57_random.txt AC 1 ms 256 KB
01_58_random.txt AC 1 ms 256 KB
01_59_freedom.txt AC 1 ms 256 KB
01_60_freedom.txt AC 1 ms 256 KB
01_61_freedom.txt AC 1 ms 256 KB
01_62_full.txt AC 1 ms 256 KB
01_63_full.txt AC 1 ms 256 KB
01_64_full.txt AC 1 ms 256 KB
01_65_min.txt AC 1 ms 256 KB
01_66_min.txt AC 1 ms 256 KB
01_67_min.txt AC 1 ms 256 KB
01_68_max.txt AC 1 ms 256 KB
01_69_max.txt AC 1 ms 256 KB
01_70_max.txt AC 1 ms 256 KB
01_71_max.txt AC 1 ms 256 KB
01_72_max.txt AC 1 ms 256 KB
02_100_min.txt AC 1 ms 256 KB
02_101_min.txt AC 1 ms 256 KB
02_102_max.txt AC 25 ms 2936 KB
02_103_max.txt AC 25 ms 2936 KB
02_104_max.txt AC 25 ms 2936 KB
02_105_max.txt AC 26 ms 2936 KB
02_106_max.txt AC 25 ms 2936 KB
02_73_random.txt AC 20 ms 2552 KB
02_74_random.txt AC 23 ms 2936 KB
02_75_random.txt AC 15 ms 1788 KB
02_76_random.txt AC 22 ms 2808 KB
02_77_random.txt AC 10 ms 1532 KB
02_78_random.txt AC 18 ms 2552 KB
02_79_random.txt AC 6 ms 1024 KB
02_80_random.txt AC 24 ms 2936 KB
02_81_random.txt AC 24 ms 2808 KB
02_82_random.txt AC 19 ms 2552 KB
02_83_random.txt AC 12 ms 1532 KB
02_84_random.txt AC 13 ms 1660 KB
02_85_random.txt AC 22 ms 2808 KB
02_86_random.txt AC 19 ms 2552 KB
02_87_random.txt AC 8 ms 1152 KB
02_88_random.txt AC 22 ms 2808 KB
02_89_random.txt AC 22 ms 2808 KB
02_90_random.txt AC 7 ms 1024 KB
02_91_random.txt AC 4 ms 640 KB
02_92_random.txt AC 12 ms 1660 KB
02_93_freedom.txt AC 17 ms 2552 KB
02_94_freedom.txt AC 9 ms 1532 KB
02_95_freedom.txt AC 12 ms 1788 KB
02_96_full.txt AC 4 ms 640 KB
02_97_full.txt AC 22 ms 2808 KB
02_98_full.txt AC 17 ms 2680 KB
02_99_min.txt AC 1 ms 256 KB