Submission #158935


Source Code Expand

Copy
#include<vector>
#include<cmath>
#include<map>
#include<cstdlib>
#include<iostream>
#include<sstream>
#include<fstream>
#include<string>
#include<algorithm>
#include<cstring>
#include<cstdio>
#include<set>
#include<stack>
#include<bitset>
#include<functional>
#include<ctime>
#include<queue>
#include<deque>
#include<complex>
using namespace std;
#define pb push_back
#define pf push_front
typedef long long lint;
typedef complex<double> P;
#define mp make_pair
#define fi first
#define se second
typedef pair<int,int> pint;
#define All(s) s.begin(),s.end()
#define rAll(s) s.rbegin(),s.rend()
#define REP(i,a,b) for(int i=a;i<b;i++)
#define rep(i,n) REP(i,0,n)
lint a[100010],d[100010];
//priority_queue<pint> q;
int main()
{
	lint hi=12345678901234LL,lo=0,k;int n;
	cin>>k;cin>>n;
	rep(i,n) cin>>a[i]>>d[i];
	while(hi>lo){
		lint mi=(hi+lo)/2,sum=0;
		rep(i,n){
			if(a[i]<=mi) sum+=(mi-a[i])/d[i]+1;
		}
		if(sum>=k) hi=mi;else lo=mi+1;
	}
	lint sum=0,out=0;
	rep(i,n){
		lint num=0;
		if(a[i]<=lo) num=(lo-a[i])/d[i]+1;
		sum+=num;out+=num*a[i]+num*(num-1)/2*d[i];
	}
	cout<<out-(sum-k)*lo<<endl;
}

Submission Info

Submission Time
Task C - 増築王高橋君
User sky58
Language C++ (G++ 4.6.4)
Score 100
Code Size 1157 Byte
Status AC
Exec Time 165 ms
Memory 2352 KB

Judge Result

Set Name Sample Subtask1 Subtask2 Subtask3 Subtask4
Score / Max Score 0 / 0 30 / 30 10 / 10 15 / 15 45 / 45
Status
AC × 2
AC × 14
AC × 26
AC × 38
AC × 52
Set Name Test Cases
Sample subtask0_sample-01.txt, subtask0_sample-02.txt
Subtask1 subtask0_sample-01.txt, subtask0_sample-02.txt, subtask1_01.txt, subtask1_02.txt, subtask1_03.txt, subtask1_04.txt, subtask1_05.txt, subtask1_06.txt, subtask1_07.txt, subtask1_08.txt, subtask1_09.txt, subtask1_10.txt, subtask1_11.txt, subtask1_12.txt
Subtask2 subtask0_sample-01.txt, subtask0_sample-02.txt, subtask1_01.txt, subtask1_02.txt, subtask1_03.txt, subtask1_04.txt, subtask1_05.txt, subtask1_06.txt, subtask1_07.txt, subtask1_08.txt, subtask1_09.txt, subtask1_10.txt, subtask1_11.txt, subtask1_12.txt, subtask2_01.txt, subtask2_02.txt, subtask2_03.txt, subtask2_04.txt, subtask2_05.txt, subtask2_06.txt, subtask2_07.txt, subtask2_08.txt, subtask2_09.txt, subtask2_10.txt, subtask2_11.txt, subtask2_12.txt
Subtask3 subtask0_sample-01.txt, subtask0_sample-02.txt, subtask1_01.txt, subtask1_02.txt, subtask1_03.txt, subtask1_04.txt, subtask1_05.txt, subtask1_06.txt, subtask1_07.txt, subtask1_08.txt, subtask1_09.txt, subtask1_10.txt, subtask1_11.txt, subtask1_12.txt, subtask2_01.txt, subtask2_02.txt, subtask2_03.txt, subtask2_04.txt, subtask2_05.txt, subtask2_06.txt, subtask2_07.txt, subtask2_08.txt, subtask2_09.txt, subtask2_10.txt, subtask2_11.txt, subtask2_12.txt, subtask3_01.txt, subtask3_02.txt, subtask3_03.txt, subtask3_04.txt, subtask3_05.txt, subtask3_06.txt, subtask3_07.txt, subtask3_08.txt, subtask3_09.txt, subtask3_10.txt, subtask3_11.txt, subtask3_12.txt
Subtask4 subtask0_sample-01.txt, subtask0_sample-02.txt, subtask1_01.txt, subtask1_02.txt, subtask1_03.txt, subtask1_04.txt, subtask1_05.txt, subtask1_06.txt, subtask1_07.txt, subtask1_08.txt, subtask1_09.txt, subtask1_10.txt, subtask1_11.txt, subtask1_12.txt, subtask2_01.txt, subtask2_02.txt, subtask2_03.txt, subtask2_04.txt, subtask2_05.txt, subtask2_06.txt, subtask2_07.txt, subtask2_08.txt, subtask2_09.txt, subtask2_10.txt, subtask2_11.txt, subtask2_12.txt, subtask3_01.txt, subtask3_02.txt, subtask3_03.txt, subtask3_04.txt, subtask3_05.txt, subtask3_06.txt, subtask3_07.txt, subtask3_08.txt, subtask3_09.txt, subtask3_10.txt, subtask3_11.txt, subtask3_12.txt, subtask4_01.txt, subtask4_02.txt, subtask4_03.txt, subtask4_04.txt, subtask4_05.txt, subtask4_06.txt, subtask4_07.txt, subtask4_08.txt, subtask4_09.txt, subtask4_10.txt, subtask4_11.txt, subtask4_12.txt, subtask4_13.txt, subtask4_14.txt
Case Name Status Exec Time Memory
subtask0_sample-01.txt AC 19 ms 796 KB
subtask0_sample-02.txt AC 20 ms 800 KB
subtask1_01.txt AC 19 ms 800 KB
subtask1_02.txt AC 20 ms 928 KB
subtask1_03.txt AC 21 ms 804 KB
subtask1_04.txt AC 21 ms 924 KB
subtask1_05.txt AC 23 ms 928 KB
subtask1_06.txt AC 21 ms 748 KB
subtask1_07.txt AC 22 ms 924 KB
subtask1_08.txt AC 22 ms 804 KB
subtask1_09.txt AC 22 ms 732 KB
subtask1_10.txt AC 20 ms 844 KB
subtask1_11.txt AC 21 ms 924 KB
subtask1_12.txt AC 21 ms 804 KB
subtask2_01.txt AC 19 ms 928 KB
subtask2_02.txt AC 20 ms 800 KB
subtask2_03.txt AC 21 ms 808 KB
subtask2_04.txt AC 21 ms 928 KB
subtask2_05.txt AC 22 ms 712 KB
subtask2_06.txt AC 28 ms 928 KB
subtask2_07.txt AC 24 ms 924 KB
subtask2_08.txt AC 25 ms 808 KB
subtask2_09.txt AC 26 ms 932 KB
subtask2_10.txt AC 27 ms 800 KB
subtask2_11.txt AC 28 ms 928 KB
subtask2_12.txt AC 25 ms 800 KB
subtask3_01.txt AC 22 ms 924 KB
subtask3_02.txt AC 20 ms 928 KB
subtask3_03.txt AC 25 ms 744 KB
subtask3_04.txt AC 148 ms 2348 KB
subtask3_05.txt AC 27 ms 932 KB
subtask3_06.txt AC 26 ms 800 KB
subtask3_07.txt AC 55 ms 1140 KB
subtask3_08.txt AC 131 ms 1964 KB
subtask3_09.txt AC 158 ms 2332 KB
subtask3_10.txt AC 160 ms 2340 KB
subtask3_11.txt AC 158 ms 2352 KB
subtask3_12.txt AC 91 ms 1704 KB
subtask4_01.txt AC 163 ms 2264 KB
subtask4_02.txt AC 21 ms 928 KB
subtask4_03.txt AC 26 ms 804 KB
subtask4_04.txt AC 162 ms 2344 KB
subtask4_05.txt AC 21 ms 808 KB
subtask4_06.txt AC 21 ms 808 KB
subtask4_07.txt AC 21 ms 804 KB
subtask4_08.txt AC 21 ms 796 KB
subtask4_09.txt AC 130 ms 1960 KB
subtask4_10.txt AC 21 ms 928 KB
subtask4_11.txt AC 165 ms 2284 KB
subtask4_12.txt AC 162 ms 2340 KB
subtask4_13.txt AC 163 ms 2340 KB
subtask4_14.txt AC 20 ms 920 KB